For some reason the pffacebookutils session does not open/remain open.
I cannot publish to facebook and am getting this error. I assure you the currentuser is linked with facebook.
if ([[PFFacebookUtils session] isOpen]) {
/*
* if the current session has no publish permission we need to reauthorize
*/
if ([[[PFFacebookUtils session] permissions]indexOfObject:#"publish_actions"] == NSNotFound) {
[[PFFacebookUtils session] requestNewPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
[self publishFacebookStory: object message:message];
}];
}else{
[self publishFacebookStory: object message:message];
}
}else{
/*
* open a new session with publish permission
*/
[[PFFacebookUtils session] openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
[self publishFacebookStory: object message:message];
}else{
NSLog(#"%#",error);
}
}];
}
Some related error output:
FBSDKLog: Error for request to endpoint '/me/fitness.runs': An open FBSession must be specified for calls to this endpoint.
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x17547aa80 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}}
PFKeychainStore failed to get object for key 'currentUser'
thanks for any help!
This was temporarily fixed, and I actually no longer recall what the actual issue was...but I now use parse facebook utils v4 and facebook sdk 4.0+ and the issue no longer exists because there is no such thing as sessions anymore.
Related
i have integerated facebook sdk latest, i create App on developer with my acoount ABC ....and use Facebook App id . All is fine if i loging in my Ios app with my ABC account to loging with facebook.it post on my wall successfully .
But if i use any other Account to loging with facebook . i loged in successfully but when i post i got error .
**I am getting this erro**r
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x22689930 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 200;
message = "(#200) The user hasn't authorized the application to perform this action";
type = OAuthException;
};
};
code = 403;
}, com.facebook.sdk:ErrorSessionKey=, expirationDate: 2014-08-15 08:56:01 +0000, refreshDate: 2014-06-16 10:10:43 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
status,
permission
)>}
For Posting
-(void) post:(NSString *)postString
{
if (FBSession.activeSession.state == FBSessionStateOpen|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended)
{
NSArray *permissionsNeeded = #[#"publish_stream"];
[FBRequestConnection startWithGraphPath:#"/me/permissions"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
NSDictionary *currentPermissions= [(NSArray *)[result data] objectAtIndex:0];
NSMutableArray *requestPermissions = [[NSMutableArray alloc] initWithArray:#[]];
for (NSString *permission in permissionsNeeded){
if (![currentPermissions objectForKey:permission]){
[requestPermissions addObject:permission];
}
}
if ([requestPermissions count] < 1){
[FBSession.activeSession requestNewPublishPermissions:requestPermissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
[self makeRequestToUpdateStatus:postString];
} else {
NSLog(#"%#",[error description]);
}
}];
} else {
[self makeRequestToUpdateStatus:postString];
}
} else {
NSLog(#"%#",[error description]);
}
}];
}
else
{
}
}
For Login
-(void)loginToFacebook
{
NSLog(#"the facebook login called ");
if (!(FBSession.activeSession.state == FBSessionStateOpen || FBSession.activeSession.state == FBSessionStateOpenTokenExtended)){
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_stream",
nil];
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
dispatch_async( dispatch_get_main_queue(), ^{
[self sessionStateChanged:session
state:status
error:error];
});
}];
}
else
{
}
}
Hm, the message indicates you do not request the correct permissions from the user.
Perhaps you requested more before, and therefore it still works with your ABC account, because you 'authorized' the app already with that account at that time. So Facebook still sees that ABC authorized the app to post on the wall.
Edit: added the instructions below in response to your comments:
You can find a list with permissions you can ask for here. Note that with API v 2.0 if you ask for more than a few basic permissions (and posting on a wall is not such a basic permission) you will need to have Facebook 'approve' your app (unless you started your app before April 2014, in which case you can probably keep using v1.0 and not need approval until April 2015).
De-authorizing your own app can be done by logging in as that user, go to settings (menu top right), choose applications at the left and click the 'x' next to your application.
Steps
https://developers.facebook.com/apps
Select Your App then follow steps.
in **Settings** -> Basic
1. add contact Email
2. Bundle id
3. Url Scheme Suffix (like Your app name)
Then Save
In **Status & Review**
1.Do you want to make this app and all its live features available to the general public?
Set Yes
May be Useful
I am using the Facebook SDK in order to get user groups in an application
but I am getting a null access token.
My code in viewDidLoad is as follows.
- (void)viewDidLoad
{
[super viewDidLoad];
self.session = [[FBSession alloc] initWithAppID:appID permissions:#[#"basic_info",#"user_groups",#"email"] defaultAudience:FBSessionDefaultAudienceEveryone urlSchemeSuffix:nil tokenCacheStrategy:nil];
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info",#"user_groups",#"email"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(#"Error in Session Opening %#",error.description);
NSLog(#"access Token %#",session.accessTokenData.accessToken);
[FBRequestConnection startWithGraphPath:#"me/groups" parameters:nil HTTPMethod:#"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"%#",result);
}else
{
NSLog(#"Error %#",error.description);
}
}];
}];
}
OUTPUT of this code is :-
Error in Session Opening (null)
access Token (null)
Error Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1090acc80 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}}
As you can see the access token is null..
What am I doing wrong ?
Is there something extra which should be added in this code ?
Thanks
you want this:
session.accessTokenData.accessToken
where 'session' is your FBSession
which you can get from...
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded)
{
// If there's one, just open the session silently, without showing the user the login UI
[FBSession openActiveSessionWithReadPermissions:#[#"public_profile", #"email"]
allowLoginUI:NO
completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
NSLog(#"%#", session.accessTokenData.accessToken);
}];
}
Are you using the correct facebook appID? Why not specify nil, i.e.,
self.session = [[FBSession alloc] initWithAppID:nil permissions:#[#"basic_info",#"user_groups",#"email"] defaultAudience:FBSessionDefaultAudienceEveryone urlSchemeSuffix:nil tokenCacheStrategy:nil];
That'd be one less place to go wrong. As it says in FBSession class reference
If nil is passed in the default App ID will be obtained from a call to
<[FBSession defaultAppID]>. The default is nil.
Also, you don't have to alloc/init the FBSession yourself, but if you want to, you should follow the 3-step process specified in FBSession lifecycle, including checking for FBSessionStateCreated before proceeding with one of the open methods, as quoted from FBSession lifecycle:
Instead of calling one of the static openActiveSession* methods, your app can achieve the same flow following these steps:
Call one of the FBSession instance init functions.
Check if the state value has transitioned to FBSessionStateCreated.
If the state value is FBSessionStateCreated, call one of the
FBSession instance
open functions.
I am using Facebook Leader to post score that is working fine in the iOS 7 when I use iPhone but it is giving null Access token when I use iPad with iOS 7.When I used older version iPad then also it was working fine.I am getting this issue only when I use iPad with iOS.
Code Snippet:
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(#" access==%#",[FBSession activeSession].accessTokenData.accessToken);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[FBSession activeSession].accessTokenData.accessToken,#"access_token",[NSString stringWithFormat:#"%d",time], #"score",nil];
[FBRequestConnection startWithGraphPath:#"me/scores"
parameters:params
HTTPMethod:#"POST"
completionHandler:
^(FBRequestConnection *connection, id result, NSError *error) {
// Handle results
NSLog(#"result==%# eror==%#",result,error);
}];
}];
Error Message:
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x16573530 {com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}
I am stuck here.please suggest some way out.Is anything wrong with my implementation.
You should use session instead of [FBSession activeSession] because Currently in this Block method you are Quering access token form previous session i-e [FBSession activeSession] and not session that is returned from [FBSession openActiveSessionWithPublishPermissions:^block . Or At-least assign [FBSession setActiveSession:session]; before you get accesstoken.
I am following the sample codes on Facebook developer's site and I cannot fetch my name for example. I am using this code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen) {
NSLog(#"Session is not open");
// create a fresh session object
appDelegate.session = [[FBSession alloc] init];
// if we don't have a cached token, a call to open here would cause UX for login to
// occur; we don't want that to happen unless the user clicks the login button, and so
// we check here to make sure we have a token before calling open
if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
// even though we had a cached token, we need to login to make the session usable
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// we recurse here, in order to update buttons and labels
}];
}
} else {
NSLog(#"Session is open");
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
NSLog(#"logged in : %#, id: %#",user.name,user.id);
} else {
NSLog(#"error: %#", error);
}
}];
}
}
so when the session is open, I see this output:
Session is open
error: Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1fd60620 {com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}
On facebook app page, I have set AppId to 0 since it is not uploaded yet. BundleId is set correctly.
What am I missing or is there any other way to do so?
You should set your appDelegate.session as the active session by calling
[FBSession setActiveSession:appDelegate.session];
when you open it.
This is because FBRequest's requestForMe method uses the active session (as stated in the docs).
Calling this:
[[self session] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
and I'm getting an error:
(lldb) po [error userInfo]
(id) $0 = 0x1fde09c0 {
"com.facebook.sdk:ErrorInnerErrorKey" = "Error Domain=com.apple.accounts Code=8 \"The operation couldn\U2019t be completed. (com.apple.accounts error 8.)\"";
"com.facebook.sdk:ErrorLoginFailedReason" = "com.facebook.sdk:ErrorLoginFailedReason";
}
I know that "com.apple.accounts error 8" means ACErrorAccessInfoInvalid, but I have no idea how I can fix that, as the code that calls this is buried in the framework.
My default permissions were the problem. Once I removed all the permissions from the creation of the initial FBSession, it worked. HOWEVER I now have to figure out how to ask for those permissions later on.