2017-02-20 14 views
0

私の小さなxamarin iOSアプリでFacebook共有機能を実装しようとしています。私はすでにの最新バージョンをダウンロードしています。FacebookのiOS SDKはnugetからダウンロードしましたが、使用方法はわかりません。既にそれをしている人はいますか?彼はそれについて私にいくつかの普通の情報を送ることができますか? 多くの方々に感謝いたします:)ios.XamarinのFacebook Share

答えて

0

私はtwitterとfbの共有を実装しました。

のiOSあなたがアクセストークンを取得するためには使用できません使用IOSからと場合 OAuth2Authenticatorをネイティブの社会サービスを使用して共有することができますバージョン

は、使用して投稿FB graph

public void ShareViaSocial(string serviceType, string urlToShare) 
     { 
      socialKind = serviceType == "Twitter" ? SLServiceKind.Twitter : SLServiceKind.Facebook; 

      if (SLComposeViewController.IsAvailable(socialKind)) 
      { 
       _socialComposer = serviceType == "Twitter" ? SLComposeViewController.FromService(SLServiceType.Twitter) : SLComposeViewController.FromService(SLServiceType.Facebook); 
       _socialComposer.AddUrl(new Uri(urlToShare)); 

       viewController.PresentViewController(_socialComposer, true,() => 
       { 
        _socialComposer.CompletionHandler += (result) => 
        { 
         Device.BeginInvokeOnMainThread(() => 
         { 
          viewController.DismissViewController(true, null); 

          if (result == SLComposeViewControllerResult.Done) 
          { OnShare(this, ShareStatus.Successful); } 
          else 
          { OnShare(this, ShareStatus.NotSuccessful); } 
         }); 
        }; 

       }); 
      } 

      //If user doest have fb app and no credential for social services we use fb graph 
      else if (socialKind == SLServiceKind.Facebook) 
      { 
       var auth = new OAuth2Authenticator(
       clientId: SharedConstants.FacebookLiveClientId, 
       scope: SharedConstants.FacebookScopes, 
       authorizeUrl: new Uri(SharedConstants.FacebookAuthorizeUrl), 
       redirectUrl: new Uri(SharedConstants.FacebookRedirectUrl)); 
       viewController.PresentViewController((UIViewController)auth.GetUI(), true, null); 
       auth.AllowCancel = true; 
       auth.Completed += (s, e) => 
       { 
        //hide the webpage after completed login 
        viewController.DismissViewController(true, null); 
        // We presented the UI, so it's up to us to dimiss it on iOS. 


        if (e.IsAuthenticated) 
        { 
         Account fbAccount = e.Account; 
         Dictionary<string, string> dictionaryParameters = new Dictionary<string, string>() { { "link", urlToShare } }; 
         var requestUrl = new Uri("https://graph.facebook.com/me/feed"); 
         var request = new OAuth2Request(SharedConstants.requestMethodPOST, requestUrl, dictionaryParameters, fbAccount); 

         request.GetResponseAsync().ContinueWith(this.requestResult); 
        } 
        else { OnShare(this, ShareStatus.NotSuccessful); } 
       }; 
       auth.Error += Auth_Error; 
      } 
      //If user doest have twitter app and no credential for social services we use xanarub auth for token and call twitter api for sending tweets 

      else 
      { 
       var auth = new OAuth1Authenticator(
           SharedConstants.TwitterConsumerKey, 
           SharedConstants.TwitterConsumerSecret, 
           new Uri(SharedConstants.TwitterRequestUrl), 
           new Uri(SharedConstants.TwitterAuth), 
           new Uri(SharedConstants.TwitterAccessToken), 
           new Uri(SharedConstants.TwitterCallBackUrl)); 

       auth.AllowCancel = true; 
       // auth.ShowUIErrors = false; 
       // If authorization succeeds or is canceled, .Completed will be fired. 
       auth.Completed += (s, e) => 
       { 
        // We presented the UI, so it's up to us to dismiss it. 
        viewController.DismissViewController(true, null); 

        if (e.IsAuthenticated) 
        { 
         Account twitterAccount = e.Account; 
         Dictionary<string, string> dictionaryParameters = new Dictionary<string, string>() { { "status", urlToShare } }; 
         var request = new OAuth1Request(SharedConstants.requestMethodPOST, new Uri("https://api.twitter.com/1.1/statuses/update.json"), dictionaryParameters, twitterAccount); 
         //for testing var request = new OAuth1Request("GET",new Uri("https://api.twitter.com/1.1/account/verify_credentials.json "),null, twitterAccount); 
         request.GetResponseAsync().ContinueWith(this.requestResult); 
        } 
        else { OnShare(this, ShareStatus.NotSuccessful); } 
       }; 
       auth.Error += Auth_Error; 
       //auth.IsUsingNativeUI = true; 
       viewController.PresentViewController((UIViewController)auth.GetUI(), true, null); 
      } 
     } 
関連する問題