Facebook SDK 3.1 - com.facebook.sdk 使用 [facebook authorize:permissions] 进行身份验证时出现错误 5 [英] Facebook SDK 3.1 - com.facebook.sdk Error 5 when authenticating with [facebook authorize:permissions]

查看:18
本文介绍了Facebook SDK 3.1 - com.facebook.sdk 使用 [facebook authorize:permissions] 进行身份验证时出现错误 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用以下授权方法进行身份验证时,我收到了带有 startWithGraphPath 和 startForMeWithCompletionHandler 的 com.facebook.sdk 错误 5,但没有使用 requestWithGraphPath.我成功地获得了令牌(在 didLogin 中打印)并使用 requestwithGraphPath 获得了我想要的任何东西,但我无法使用其他方法.如果有人遇到同样的问题或类似的事情或有任何想法,如果你分享我会很高兴.

When authenticating with following authorization method i'm getting com.facebook.sdk error 5 with startWithGraphPath and startForMeWithCompletionHandler but not with requestWithGraphPath. I'm succesfully getting token (printing in didLogin) and getting anything which i want with requestwithGraphPath but i'm unable to get work with other methods. If anybody encountered with same issue or something similar or has any idea, i'd be happy if you share it.

谢谢

方法:

NSArray *permissions = [[NSArray alloc] initWithObjects: @"user_likes",@"offline_access",@"read_stream",@"publish_stream",nil];
[_facebook authorize:permissions];

推荐答案

以下解决方案对我有用.但是,如果您要存储永久访问令牌,则需要确保用户没有删除应用程序权限,否则会出错.您可以使用 requestWithGraphPath -> "me/permissions" 进行检查.

Following solution worked for me. But if you're storing a permanent access token, you need to be sure user not removed application permissions otherwise it will give an error. And you can check that with requestWithGraphPath -> "me/permissions".

应用程序初始化函数(例如:didFinishLaunchingWithOptions/或您初始化 Facebook 对象的位置同时需要为 fbsessiondelegate)

Application Init Function (e.g.:didFinishLaunchingWithOptions/or where you init your Facebook object which needs to be fbsessiondelegate in the mean time)

...    
NSArray* permissions = [[NSArray alloc] initWithObjects:@"user_likes",@"offline_access", nil];

        FBSession*oursession = [[FBSession alloc] initWithPermissions:permissions];
...

FBDidLogin 函数:

FBDidLogin function:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

图api请求函数示例:

Example graph api request function:

NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
        NSString *key = [userDefaults stringForKey:@"FBAccessTokenKey"];

    FBRequest* ourcon = [[FBRequest alloc] initWithSession:oursession graphPath:@"me/likes" parameters:params HTTPMethod:@"GET"];

            [ourcon startWithCompletionHandler: ^(FBRequestConnection *connection, id<FBGraphUser> result, NSError *error){
                if(error)
                {
                    //NSLog(error.code);
                    return;
                }

                NSArray* collection = (NSArray*)[result data];
                NSLog(@"You have %d like", [collection count]);

                NSDictionary* name = [collection objectAtIndex:14];
                NSLog(@"Like Name: %@", [name objectForKey:@"name"]);
            }];

这篇关于Facebook SDK 3.1 - com.facebook.sdk 使用 [facebook authorize:permissions] 进行身份验证时出现错误 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆