菜鸟教程小白 发表于 2022-12-13 10:45:09

ios - 尝试登录 iOS sdk 时无法通过 FBSDKLoginKit 获取访问 token


                                            <p><p>我正在使用 facebook sdk 在 facebook 上共享文本,但在尝试登录时无法获取访问 token 。登录成功,但没有获得任何访问 token 。
因此,如果没有访问 token ,我将无法在 facebook 上分享文本。
我的代码如下</p>

<pre><code>FBSDKLoginManager *login = [ init];
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {


if () {
    [[
      initWithGraphPath:@&#34;me/feed&#34;
      parameters: @{ @&#34;message&#34; : @&#34;hello world&#34;}
      HTTPMethod:@&#34;POST&#34;]
   startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
         if (!error) {
             NSLog(@&#34;Post id:%@&#34;, result[@&#34;id&#34;]);
         }
   }];
}

if (error) {
    // Process error
} else if (result.isCancelled) {

    // Handle cancellations
} else {
    // If you ask for multiple permissions at once, you
    // should check if specific permissions missing
    if () {
      // Do work
    }
}
</code></pre>

<p>}];</p>

<p>我在 FBSDKLoginManager 对象的处理程序 block 中得到结果,没有错误,但它不包含 token 或其他数据</p>

<p>输出如下</p>

<p> <img src="/image/YeHft.png" alt="enter image description here"/> </p>

<p>请告诉我如何解决这个问题
谢谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>试试这个代码。基于 Facebook SDK 4.0 版</p>

<p><strong>AppDalegate.m</strong></p>

<pre><code>- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [ application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}
</code></pre>

<p><strong>ViewController.m</strong></p>

<pre><code>- (IBAction)btnFacebookPressed:(id)sender {
    FBSDKLoginManager *login = [ init];
    handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
   {
         if (error)
         {
             // Process error
         }
         else if (result.isCancelled)
         {
             // Handle cancellations
         }
         else
         {
             if ()
             {
               NSLog(@&#34;result is:%@&#34;,result);
               ;
               ;
             }
         }
   }];
}

-(void)fetchUserInfo
{
    if ()
    {
      NSLog(@&#34;Token is available : %@&#34;,[tokenString]);

      [[ initWithGraphPath:@&#34;me&#34; parameters:@{@&#34;fields&#34;: @&#34;id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists&#34;}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
               NSLog(@&#34;resultis:%@&#34;,result);
             }
             else
             {
               NSLog(@&#34;Error %@&#34;,error);
             }
         }];

    }

}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 尝试登录 iOS sdk 时无法通过 FBSDKLoginKit 获取访问 token ,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/30248048/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/30248048/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 尝试登录 iOS sdk 时无法通过 FBSDKLoginKit 获取访问 token