I'm using test users with the IOS Facebook SDK. I create test users and retrieve one userID. Then I create a graphPath string that resembles the "/me" path: /{user-id}
NSString* userId = [[self.testUserTokens objectAtIndex:0] userID];
NSString* graphPath = [NSString stringWithFormat:#"/%#", userId];
Then I make the graph request.
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:#{#"fields": #"name, id"}];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:request
completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"data = %#", result);
if (error)
NSLog(#"error = %#", error);
//TODO: process me information
}];
[connection start];
This returns a 400 "Bad Request" error. I don't understand why at all, I thought I was following the correct format from the Facebook documentation. Does anyone know what I'm doing wrong? I figure it's just a small mistake I can't notice.
Edit: After using the Facebook Graph Explorer, it appears that a /{user-id} request works correctly, using my own Facebook User ID for instance. But it does not work with the IDs of my test users, which I can retrieve either in the Roles panel of Facebook Developers Dashboard or in my app using the method above. For my own ID, I notice that it is different whether I'm retrieving it from the Graph Explorer or from my app, which is logical considering Facebook explains IDs differ based on the app being used, I believe.
Doing the request above using my own personal ID, retrieved using [FBSDKAccessToken currentAccessToken].userId works perfectly fine. So the issue seems to stem from the test user IDs.
Facebook Developer support has resolved this issue for me after I submitted it as a bug.
Turns out it was required to pass a user access token, which I assume is required when wanting to access direct {user-id} data instead of "me" data.
The code thus looks like this:
[testManager requestTestAccountTokensWithArraysOfPermissions: #[[NSSet setWithObjects:#"email", #"user_friends", nil], [NSSet setWithObjects:#"email", #"user_friends", nil]] createIfNotFound:NO completionHandler:^(NSArray* tokens, NSError* error)
{
self.testUserTokens = tokens;
NSLog(#"token1 = %#", [[self.testUserTokens objectAtIndex:0] tokenString]);
NSString* userId = [[self.testUserTokens objectAtIndex:0] userID];
NSString *accessToken = [[self.testUserTokens objectAtIndex:0] tokenString];
NSString* graphPath = [NSString stringWithFormat:#"/%#", userId];
NSLog(#"graphPath = %#", graphPath);
[[[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:#{#"fields": #"name, id, email"} tokenString:accessToken version:nil HTTPMethod:#"GET"] startWithCompletionHandler:^(FBSDKGraphRequestConnection* connection, id result, NSError* error)
{
NSLog(#"data = %#", result);
if (error)
NSLog(#"error = %#", error);
}];
Related
I try to publish comments on Pages photos posts by using the following code :
NSDictionary *params = #{#"message" : #"New Comment"};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:#"/%#/comments", objectId]
parameters:params
HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(error){
NSLog(#"Error Comment %#", [error description]);
}
else{
NSLog(#"Result Comment %#", [result description]);
}
}];
It works (worked) when I used NSDictionary *params = #{#"message" : #"New Comment"};
But when I tried to use attachment_url as parameters value but then I get this error :
error = {
message:"(#1705) There was an error posting to this wall";
type:"OAuthException";
code:1705
};
I tried to make the calls by using curl and Facebook graph-api explorer and I get same errors.
The page I'm trying to comment on doesn't seem to have particular restrictions.
Now I'm getting the following error :
FBSDKGraphRequestErrorGraphErrorCode=368, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 368;
message = "It looks like you were misusing this feature by going too fast. You've been blocked from using it.Learn more about blocks in the Help Center.";
type = OAuthException;
};
};
code = 400;
}}
I guess I reach a limit of something but I don't know which one. What I am suppose to do know to be able to perform requests on {object-id}/comments again ?
Facebook does not and will not officially post any call limits. The reason they give is: "If you are using the platform responsibility you will not hit any rate limits".
It appears to me you are attempting to spam comments to multiple objects and of course they will block this.
So what is you are trying to do?
I am working on a Facebook IOS app to fetch user data(Public Profile,Email) from the Facebook.After implementing login process i am able to fetch first name,last name and url for profile picture of the User but the email i am getting is null. i have passed the permission for getting public Profile and Emial.but i am not getting Email Of the person.
I am using facebook SDK for ios V4.0.1
Here is my code
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me"
parameters:#{#"fields": #"first_name, last_name, picture, email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString *firstName = [NSString stringWithFormat:#"%#",[result objectForKey:#"first_name"]];
NSString *lastName = [NSString stringWithFormat:#"%#",[result objectForKey:#"last_name"]];
NSString *email = [NSString stringWithFormat:#"%#",[result objectForKey:#"email"]];
NSString *picurl = [NSString stringWithFormat:#"%#",[result objectForKey:#"picture"]];
NSLog(#"email is %#", [result objectForKey:#"email"]);
NSLog(#"picture is %#", [result objectForKey:#"picture"]);
}
else{
NSLog(#"%#", [error localizedDescription]);
}
}];
I am getting the Following Output:
email is (null)
picture is {
data = {
"is_silhouette" = 0;
url = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/p50x50 **************_************_n.jpg?oh=ed5fd60c770cb5f34424b3fcfb4ca174&oe=559F472D&__gda__=1437970763_989a264cf7ec16f5d51b0a58b7e7f609";
};
}
why i am not getting Email Address of the User
While logging. You must ask user permission for email or else you would get email as (null).
Would not fetch Email ID
FBSDKLoginButton *loginView = [[FBSDKLoginButton alloc] init];
loginView.readPermissions = #[#"public_profile"];
IF you login with above permission then you would not be able to get email id it will always be return (null).
Would fetch Email ID with Public profile
FBSDKLoginButton *loginView = [[FBSDKLoginButton alloc] init];
loginView.readPermissions = #[#"email"];
Our app gets public_profile permission automatically upon any successful login but it does not get email.
Same goes for custom login as well.
Refer to :https://developers.facebook.com/docs/facebook-login/ios/v2.3#login-apicalls
If you were to assume the logic that setting FBSDKLoginButton.readPermissions to ["public_profile","email"] would be the way to express that you want the Facebook user's "public_profile" and their "email" address you will be sorely mistaken. Very confusing in my opinion, the following gives you both the Facebook user's public profile and their email address:
FBSDKLoginButton.readPermissions = ["email"]
I want to get facebookid of my friends. But seems like its sending different id's
The situation is i have a friends name "abc" when i loads the friends list then i am getting following response for friend "abc" from facebook
<__NSCFArray 0xce76290>(
{
id = 668201987254085;
name = "abc";
}
)
and my facebook id is "123764734754"returned by facebook
i am using below code for this
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
SLRequest *friendsListRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:URLIFY(#"https://graph.facebook.com/me/friends")
parameters:nil];
friendsListRequest.account = facebookAccount;
[friendsListRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (responseData) {
NSLog(#"Got a response: %#", [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding]);
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {
NSError *jsonError = nil;
NSDictionary *friendsListData = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingAllowFragments
error:&jsonError];
if (jsonError) {
NSLog(#"Error parsing friends list: %#", jsonError);
} else {
self.userList = friendsListData[#"data"];
}
} else {
NSLog(#"HTTP %ld returned", (long)urlResponse.statusCode);
}
} else {
NSLog(#"ERROR Connecting");
}
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
});
}];
But when i am logging in using user name "abc" then for abc (current login user) i am getting different id say "10008772786278"
same thing when i login then i got my facebook id"123764734754" but when my friend "abc" login then in his friends list response they got my id "897349579554"
why this thing happen? how to get same facebook id of the user that is returned after when he login
Please Try this code.
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error){
NSLog(#"Error :%#",error);
if (session.isOpen && !error) {
[FBRequestConnection startWithGraphPath:#"me/friends" parameters:nil HTTPMethod:#"GET" completionHandler:^(FBRequestConnection *connection,id result, NSError *error){
if (!error) {
NSLog(#"result %#",result);
[array_firendList addObjectsFromArray:[result valueForKey:#"data"]];
NSLog(#"count %ld",(unsigned long)[array_firendList count]);
}
}];
Facebook recently changed a lot of stuff, see here: https://developers.facebook.com/docs/apps/changelog
See "App-scoped User IDs", you don´t get the real IDs anymore:
To better protect people's information, when people log into a version
of your app that has been upgraded to use Graph API v2.0, Facebook
will now issue an app-scoped ID rather than that person's orginal ID
Also important:
The /me/friends endpoint no longer includes the full list of a
person's friends. Instead, it now returns the list of that person's
friends who are also using your app.
To make sure you always get an App Scoped ID, use /v2.0/{object} instead of /{object}. For example, to get the ID of the logged in user you can use /v2.0/me, for getting the friend list you can use /v2.0/me/friends. This is only necessary if your App is created before May 2014, if you created it later it will only use v2.0 anyway.
Another hint: make sure you get the IDs (with /me or /me/friends) on the same platform and of course with the same App, don´t compare the IDs you get with the Graph API Explorer (for example) with the ones you get in the App.
I am implementing the Checkins Facebook Graph API using Facebook SDK. This is the code for Checkins
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:accsstoken,#"access_token",#"253651184683030",#"place",#"I m here in this place",#"message",#"30.893075018178,75.821777459326",#"coordinates", nil];
[FBRequestConnection startWithGraphPath:#"/me/checkins"
parameters:dict
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#"Error...%#",error);
}];
When I tried this above code. It gives me following error:
error = {
code = 160;
message = "(#160) Invalid coordinates. Coordinates must contain at least latitude and longitude.";
type = OAuthException;
};
It gives the coordinates issue. Is there a different way to pass the coordinates parameters? Please help me out of this issue.
As far as I know checkins are deprecated and you should use post with place parameter.
And here is the link. Facebook SDK reference
Edit: For people who too lazy to check the link, there is the sample code from Facebook.
// Create an object
NSMutableDictionary<FBOpenGraphObject> *restaurant = [FBGraphObject openGraphObjectForPost];
// specify that this Open Graph object will be posted to Facebook
restaurant.provisionedForPost = YES;
// Add the standard object properties
restaurant[#"og"] = #{ #"title":#"Restaurant Name", #"type":#"restaurant.restaurant", #"description":#"a description", #"image":image };
// Add the properties restaurant inherits from place
restaurant[#"place"] = #{ #"location" : #{ #"longitude": #"-58.381667", #"latitude":#"-34.603333"} };
// Add the properties particular to the type restaurant.restaurant
restaurant[#"restaurant"] = #{#"category": #[#"Mexican"],
#"contact_info": #{#"street_address": #"123 Some st",
#"locality": #"Menlo Park",
#"region": #"CA",
#"phone_number": #"555-555-555",
#"website": #"http://www.example.com"}};
// Make the Graph API request to post the object
FBRequest *request = [FBRequest requestForPostWithGraphPath:#"me/objects/restaurant.restaurant"
graphObject:#{#"object":restaurant}];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Sucess! Include your code to handle the results here
NSLog(#"result: %#", result);
_objectID = [result objectForKey:#"id"];
alertTitle = #"Object successfully created";
alertText = [NSString stringWithFormat:#"An object with id %# has been created", _objectID];
[[[UIAlertView alloc] initWithTitle:alertTitle
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
}
}];
Checkins have been deprecated in favor of attaching place information to posts, or tagging places in Open Graph stories.
You can refer here
https://developers.facebook.com/docs/graph-api/reference/user/checkins/
So I'm trying to get the name of a page with the Facebook graph API using the iOS SDK:
NSDictionary* params = [NSDictionary dictionaryWithObject:#"id,name" forKey:#"fields"];
[[FBRequest requestWithGraphPath:[NSString stringWithFormat:#"%#", userId] parameters:params HTTPMethod:nil] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
name = [result objectForKey:#"name"];
//do more stuff
}];
I'm getting the error
error = {
code = 803;
message = "(#803) Some of the aliases you requested do not exist: (null)";
type = OAuthException;
};
My accesstoken is valid and it does work when I'm using the Graph API Explorer with the GET request 5120148605?fields=id,name,about,bio.
Anyone having an idea of this weird behaviour?
I now resolved this by userId = [NSString stringWithFormat:#"%#", userId]. Seems like I need this for pages but not for users.
I don't know why this is present or if someone else encountered this problem, but that's my way of solving it.