{com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 2500;
"fbtrace_id" = DiBO16GER0C;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0}
我正面临上述错误。我知道这已经讨论过但是他们使用FBSession
修复了。在最新的SDK中,我没有看到FBSession。请帮助我,我被困在这一整天。
问题来自: 我有3页(登录页面,用户名页面,查找朋友页面)。在登录页面我只是通过Facebook验证并从graphAPI获取用户信息它工作正常。然后来自用户这里的页面用户名正常注册过程。然后我来到找到朋友页面这里我面临的问题是,如果我带来流程(登录 - >用户名 - >找到朋友页面)我可以使用graphAPI列出Facebook好友但当我杀死应用程序并直接打开此页面时,我无法获取好友列表,显示上述错误。我不知道该怎么回事。请帮助任何人以前感受到这一点。
我的代码在下方, 寻找朋友页面:
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:url parameters:@{ @"fields": @"id,picture"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
NSLog(@"result === %@",result);
if (!error)
{}
else
{}
}];
}
else
{
NSLog(@"There is no current access token");
}
注意: 当我终止应用程序并再次返回用户名页面时,当前访问令牌为空。
答案 0 :(得分:3)
知道了!
这对某人肯定有帮助,实际上我在这个地方犯了错误,[[[FBSDKGraphRequest alloc] initWithGraphPath:url parameters:@{ @"fields": @"id,picture"}]
这种方法永远不会有访问令牌。但奇怪的是整个应用程序中都没有启用访问令牌。杀死应用程序后移动到下一页时它将为null。所以我只是将令牌字符串保存在NSUserDefaults中,如
NSString *access_token=[FBSDKAccessToken currentAccessToken].tokenString;
[NSUSER setObject:access_token forKey:@"fb_token"];
[NSUSER synchronize];
然后无论我在哪里调用graphAPI,我都会使用像tokenstring这样的方法,
[[[FBSDKGraphRequest alloc] initWithGraphPath:url parameters:@{ @"fields": @"id,picture"} tokenString:[NSUSER objectForKey:@"fb_token"] version:nil HTTPMethod:@"GET"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
}];
简单,但需要很长时间才能找到。高兴!
答案 1 :(得分:1)
这将在swift 2.0中为您提供帮助
func application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String?,
annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(
application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
答案 2 :(得分:1)
为我工作Swift 3 将此代码放在收到好友列表或fb用户数据的地方:看看
let token = FBSDKAccessToken.current().tokenString
UserDefaults.standard.setValue(token, forKey: "fb_token")
UserDefaults.standard.synchronize()
let params = ["fields": "id, first_name, last_name, name, picture"]
let graphRequest = FBSDKGraphRequest(graphPath: "/me/friends", parameters: params, tokenString: UserDefaults.standard.value(forKey: "fb_token") as! String, version: nil, httpMethod: "GET")
答案 3 :(得分:0)
我认为这是Facebook的错误,你需要以这种方式调用图形api:
NSString *graphPath = [NSString stringWithFormat:@"%@/videos?access_token=%@", @"me", [FBSDKAccessToken currentAccessToken].tokenString];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:dict tokenString:alreadyAuthToken version:@"v2.12" HTTPMethod:@"POST"];
只需将access_token放入请求网址,其他参数放入参数参数:'