Facebook的SDK 3.1 - com.facebook.sdk错误5与身份验证时,[Facebook的授权:权限] [英] Facebook SDK 3.1 - com.facebook.sdk Error 5 when authenticating with [facebook authorize:permissions]

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

问题描述

在使用下列授权方法我得到com.facebook.sdk错误5与startWithGraphPath和startForMeWithCompletionHandler但不与requestWithGraphPath验证。我成功地获得令牌(印刷在didLogin),并得到任何东西,我想用requestwithGraphPath但我无法用其他方法来获得工作。如果有人有相同的问题或遇到什么相似或有任何想法,我会很高兴,如果你分享。

感谢

方法:

 的NSArray *权限= [[NSArray的页头] initWithObjects:@user_likes,@offline_access,@read_stream,@publish_stream零]
[_facebook认证:权限]。


解决方案

以下解决方案为我工作。但是,如果你要存储一个永久的访问令牌,你需要确保用户不删除应用程序的权限,否则会给出一个错误。你可以检查与requestWithGraphPath - >我/权限

应用程序初始化函数(e.g.:didFinishLaunchingWithOptions/or,你初始化自己的Facebook对象的这需要在平均时间fbsessiondelegate 的)

  ...
NSArray的*权限= [[NSArray的页头] initWithObjects:@user_likes,@offline_access零]        FBSession * oursession = [[FBSession页头] initWithPermissions:权限]。
...

FBDidLogin功能:

  * NSUserDefaults的默认值= [NSUserDefaults的standardUserDefaults]
    [默认的setObject:Facebook的的accessToken] forKey:@FBAccessTokenKey];
    [默认的setObject:Facebook的EXPIRATIONDATE] forKey:@FBExpirationDateKey];
    [默认同步]

实例图形API请求函数:

  * NSUserDefaults的userDefaults = [NSUserDefaults的standardUserDefaults]
        的NSString *键= [userDefaults stringForKey:@FBAccessTokenKey];    FBRequest * ourcon = [[FBRequest页头] initWithSession:oursession graphPath:@我/喜欢参数:PARAMS列举HTTPMethod:@GET];            [ourcon startWithCompletionHandler:^(FBRequestConnection *连接,ID< FBGraphUser>因此,NSError *错误){
                如果(错误)
                {
                    //NSLog(error.$c$c);
                    返回;
                }                NSArray的集合* =(NSArray的*)[结果数据]
                的NSLog(@你喜欢%D,[收藏数]);                *的NSDictionary名= [集合objectAtIndex:14];
                的NSLog(@就像名称:%@,[名objectForKey:@名]);
            }];

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.

Thanks

Method:

NSArray *permissions = [[NSArray alloc] initWithObjects: @"user_likes",@"offline_access",@"read_stream",@"publish_stream",nil];
[_facebook authorize: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".

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 function:

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

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错误5与身份验证时,[Facebook的授权:权限]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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