Reputation: 618
{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}
I am facing the above error. I know this was already discussed but they fixed using FBSession
. In the Latest SDK i did not see the FBSession. Please help me i am stuck on this for whole day.
Issue coming under: I have 3 pages (Login page, username page, find friends page). In login page i just authenticate with facebook and get the user information from the graphAPI it works fine. Then come to the page username here normal registration process from user. Then i come to the find friends page here i facing the issue that is, If i come with the flow(login -> username -> find friends page) i can list the facebook friends using graphAPI BUT i could not get the friends list when i kill the app and open this page directly it shows above error. I dont know how to get back from this. Please help anybody felt this before.
My code are below, Find Friends Page:
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");
}
Note: The current access token is null when i kill the app and come back to the username page again.
Upvotes: 1
Views: 5271
Reputation: 11
Working fine for me Swift 3 Put this code where friend list or fb user data received:have look
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")
Upvotes: 1
Reputation: 21
I think it's a Facebook's bug, You need call graph api in this way:
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"];
Just put the access_token in request url, and other params put in param 'parameters:'
Upvotes: 0
Reputation: 11
This will help you in 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)
}
Upvotes: 1
Reputation: 618
Got it!
This will be surely helpful to someone, Actually i did mistake in this place, [[[FBSDKGraphRequest alloc] initWithGraphPath:url parameters:@{ @"fields": @"id,picture"}]
This method not have the access token ever. But wonder is the access token is not enable in the whole app. it will be null when i move to the next page after kill the app. So i just save the token string in NSUserDefaults like
NSString *access_token=[FBSDKAccessToken currentAccessToken].tokenString;
[NSUSER setObject:access_token forKey:@"fb_token"];
[NSUSER synchronize];
And then wherever i call the graphAPI i use this method with tokenstring like,
[[[FBSDKGraphRequest alloc] initWithGraphPath:url parameters:@{ @"fields": @"id,picture"} tokenString:[NSUSER objectForKey:@"fb_token"] version:nil HTTPMethod:@"GET"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
}];
Simple but it takes too long to find. Glad!
Upvotes: 3