In my project i am not posting anything only fetching different data from FaceBook.
some times i am getting the data but
most of the time i am getting this Error
The operation couldn’t be completed. (com.facebook.sdk error 5.)
my small code is
permissions = [[NSArray alloc] initWithObjects:#"user_friends",#"read_stream",
#"read_requests",#"user_birthday",#"user_about_me",#"user_hometown",
#"user_location",#"user_likes",#"email",
nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
NSString *queryNew55 = #"SELECT post_id,fromid,time FROM comment WHERE time > 1375553100 AND post_id IN (SELECT post_id FROM stream WHERE source_id = me())";
// Set up the query parameter
NSDictionary *queryParam15 = #{ #"q": queryNew55 };
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam15
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error in comment query");
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"comments Result: %#", result);
}
}
];
}];
I seen lots of thing on google on the same Error
and i applied that too but nothings works permanently.
in FaceBook App All the things like sandbox mode is off and bundle id are set perfectly.
any help like link or code or any thing related to this will be great Help.
I know this question is old, but my answer might help some other people.
I was getting this error after following some of their code/tutorials/documentation.
It seems there is a disconnect between their documentation and some of the sample code.
using
if (FBSession.activeSession.state != FBSessionStateCreated) {
// Create a new, logged out session.
self.facebookSession = [[FBSession alloc] init];
}
and
[self.facebookSession openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
will not result in the session being updated in
FBSession.activeSession
getting updated.
So you will have a session that is open (self.facebookSession) and a session that is crated&TokenLoaded - which is not open.
So making any calls like:
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
will fail as the FBRequestConnection uses FBSession.activeSession
So in the completion handler you can see the active session if you are going to manage the session your self.
[self.facebookSession openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
[FBSession setActiveSession:session];
// post or load user data.
}];
It seems to work for me now,
hope this helps
Related
I am using PARSE integration for facebook. I am able to successfully link the user to facebook but when i try to get facebook firiends list i get the following error.
FBRequest *request = [FBRequest requestForMyFriends];
// Send request to Facebook
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
}];
error code = 100
message = "(#100) Unknown fields: username."
type = OAuthException
desperately need help!!
The field username is no longer available with the Graph API v2.0, see https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
Endpoints no longer available in v2.0:
...
/me/username is no longer available.
-(IBAction)btnFacebookClick:(id)sender
{
NSArray *permissions = [[NSArray alloc] initWithObjects: #"user_about_me,user_birthday,user_hometown,user_location,email",#"read_mailbox",#"read_stream",nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState status,NSError *error)
{
if(error)
{
NSLog(#"session error %#",error);
}
else if(FB_ISSESSIONOPENWITHSTATE(status))
{
[self getFriendList];
}
}];
}
-(void)getFriendList
{
FBRequest *friendsRequest=[FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
{
friendsArr = [result objectForKey:#"data"];
NSLog(#"friends description :%#",[friendsArr description]);
}];
}
I've created App from https://developers.facebook.com/apps, I'm getting weird error like > FBSDKLog: FBSession: a permission request for publish or manage permissions contains unexpected read permissions
1. My Xcode Bundle ID matches with current Fb App 2. I'm using my App to publish Check Ins to my Friends
I've given permissions to Publish Check Ins are as below code
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"public_profile",
#"basic_info",
#"user_friends",
#"status_update",
#"publish_actions",
#"publish_checkins",
#"user_checkins",
nil];
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
Any Help will be appreciated -I'll provide more information if it's needed Thanks..
You will need to separate your request for read permissions from write permissions and request them from the user in that order.
To request read permissions:
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info", #"user_checkin"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
To request write permissions:
[[FBSession activeSession] requestNewPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
}];
You can read more about the new process in Facebook iOS SDK Upgrade Guide; specifically, read the section, Asking for Read & Write Permissions Separately.
I have the following code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:txtComment.text, #"message", nil];
NSString *strPicId = [[Appdel.arrFacebookImages objectAtIndex:Appdel.getIndex] valueForKey:#"id"];
NSString *strPath =[NSString stringWithFormat:#"%#/comments",strPicId];
[FBRequestConnection startWithGraphPath:strPath parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result1, NSError *error)
{
if(!error)
{
}
else
{
NSLog(#"ERROR:%#",error);
}
}];
but when it runs, it giving me error like below,
ERROR:Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xb36dd80 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 200;
message = "(#200) Requires extended permission: publish_stream";
type = OAuthException;
};
};
I have successfully logged in and I am also getting photo albums, photos, comments, but I can't post any comment on any photo.
It looks like you are missing publish permission in your access token.
You can get it with:
[FBSession openActiveSessionWithPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (FBSession.activeSession.isOpen && !error) {
// Publish the comment (your code inside) if permission was granted
[self publishComment];
}
}];
That was the code from: https://developers.facebook.com/docs/ios/publish-to-feed-ios-sdk/
I'm using die Facebook SDK 3.1.1 to implement FB Connect in my iOS application. This works fine in the simple case with either the new FB integration (logged in on iOS) or falling back to the normal authorization via web view (I do not have the native Facebook application installed in both cases).
The problem occurs when I switch the account on iOS level. Logging out and logging in with a different FB user account.
To log in/authorize I perform:
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
If then get a FBSessionStateClosedLoginFailed every time even though I perform a closeAndClearTokenInformation when that state is reached:
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
NSLog(#"Session State Changed: %u", [[FBSession activeSession] state]);
switch (state) {
case FBSessionStateOpen:
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
NSLog(#"FBSessionStateClosedLoginFailed ERROR: %#", [error description]);
[[FBSession activeSession] closeAndClearTokenInformation];
break;
default:
break;
}
However, I receive the same state on every retry. My log says the following:
FBSDKLog: FBSession **INVALID** transition from FBSessionStateCreated to FBSessionStateClosed
FBSDKLog: FBSession transition from FBSessionStateCreated to FBSessionStateCreatedOpening
FBSDKLog: FBSession transition from FBSessionStateCreatedOpening to FBSessionStateClosedLoginFailed Session State Changed: 257
FBSessionStateClosedLoginFailed TOKEN: (null)
FBSessionStateClosedLoginFailed ERROR: Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0xb24cc20 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:ErrorLoginFailedReason}
Can anyone reproduce this or has any idea where the problem might lie?
Another answer gives a way to manually resync the device with the server. I defined a method called fbRsync to call this code. Make sure to #import <Accounts/Accounts.h> in your implementation file and then define this method:
-(void)fbResync
{
ACAccountStore *accountStore;
ACAccountType *accountTypeFB;
if ((accountStore = [[ACAccountStore alloc] init]) && (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){
NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
id account;
if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0])){
[accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
//we don't actually need to inspect renewResult or error.
if (error){
}
}];
}
}
I then call fbResync if openActiveSessionWithReadPermissions yields an error:
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if(error)
{
NSLog(#"Session error");
[self fbResync];
[NSThread sleepForTimeInterval:0.5]; //half a second
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
else
[self sessionStateChanged:session state:state error:error];
}];
The half a second delay is likely unnecessary, but it currently gives me piece of mind.
This seems to solve the problem for me. I can now switch between Facebook accounts and am able to log in. Yay!
I had the same problem. Check that your FB App is enabled in Settings -> Facebook.
Mine was disabled (even though I don't remember disabling it) and once I enabled it, it was fixed.
In my test process, I've added and removed my FB App several times from my FB Account, which is linked with my iPhone. It may explain why, magically, my app was disabled.
In ios 6 with fb sdk 3.1.1. Please pass permissions param as "nil or email" in "[FBSessio openActiveSessionWithReadPermissions..." method. Here my code it was works great.
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )
-(void)showFBLogin
{
[FBSession.activeSession closeAndClearTokenInformation];
NSArray *permissions = [NSArray arrayWithObjects:#"email, publish_actions, publish_stream", nil];
#ifdef IOS_NEWER_OR_EQUAL_TO_6
permissions = nil; or NSArray *permissions = [NSArray arrayWithObjects:#"email",nil];
#endif
NSLog(#"\npermissions = %#", permissions);
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
NSLog(#"\nfb sdk error = %#", error);
switch (state) {
case FBSessionStateOpen:
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
//success
}
}];
break;
case FBSessionStateClosed:
//need to handle
break;
case FBSessionStateClosedLoginFailed:
//need to handle
break;
default:
break;
}
}];
}
I have the same problem on 3.1.3 FB SDK with iOS7.1. And I find a solution here. Hope it help!!
I have tried all answers here.
#loganathan nil permissions, #ill_always_be_a_warriors fbResync.
All of those don't work for me.
But I found it will works well when I launch the same code in iPhone 7.1 simulator
(without SSO"Single Sign On")
The same code works well on old version iOS FB SDK(not sure which version, but not 3.13)
(but no SSO will show when try to login)
So, I try to re-write a sample problem. I found several different here.
1. https://developers.facebook.com/docs/ios/getting-started Add new FacebookDisplayName
2. I modify my BundleID for iTune connect but I am not update it back to Faceboook App Dev
After modify those setting, it works on my iOS app with SSO feature.
Hope it help!!
Did you Try the RenewSystemCredential Methods? Take a look at this post:
Facebook iOS SDK extendAccessToken not Working - fbDidExtendToken not being called
I got the same error. But i used #ill_always_be_a_warriors method: -(void)fbResync but not work for me.
I finally found it's my permissions issue, i removed offline_access permission, it works, hope it helps some one.
Please help getting a larger profile picture from Facebook. My method below returns a link to a tiny one.
- (void)openSession{
NSArray *permissions = [NSArray arrayWithObject:#"email"];
NSDictionary *parameters = [NSDictionary dictionaryWithObject:
#"picture,email,name,username,location,first_name,last_name"
forKey:#"fields"];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (session.isOpen) {
[FBRequestConnection startWithGraphPath:#"me" parameters:parameters
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//save personal details using "id result"
[...saving method here...]
//manage session
[self sessionStateChanged:session state:state error:error];
}];
}
}];
}
I have also found this way: if following this link in a web browser, I can get the image larger (the bla-bla-bla is my Facebook id:)))
http://graph.facebook.com/92875029-bla-bla-bla-84538042/picture?type=large
But it looks like the link above leads to a redirect page, cos' after the image is loaded, the link is changed to :
http://profile.ak.fbcdn.net/hprofile-ak-snc6/1864-bla-bla-bbla-bla482_n.jpg
Well, never mind, I cannot use it in my method above anyway.
So actually I am getting the profile picture, but as I said, it's small.
Please help getting it larger, but within my used method. Many thanks in advance
Change your parameters to:
#"picture.type(large),email,name,username,location,first_name,last_name"