Facebook iOS SDK(Graph API) can't access public page information - ios

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.

Related

iOS Facebook graph request error when looking up {user-id} path

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);
}];

Facebook graph-API OAuthException Code:368 Misusing this feature by going too fast

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?

Set the coordinate parameter for facebook graph checkins

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/

Facebook request for friends returns 0 friends when session is open

I am building an iOS application that is connected to Facebook. I got most of the Facebook related code (pretty much copied all of it) from the TokenCacheHowTo project. I have run into two problems, one which had a simple fix, but I think may be causing my second problem.
At first the login wasn't persisting. I had copied all the code from TokenCacheHowTo, so I was confused why and looked for a solution. Eventually I found this question and it said that if I removed #[#"basic_info"] from the permissions parameter it would work. And it did. I am still confused as to why it would work. Note: I removed #[#"basic_info"] from the openSessionWithAllowLoginUI method in my app delegate.
My problem now is that I want a list of the users friends, so I do the following request in the app delegate.
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSLog(#"Under");
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
}];
This code outputs Found: 0 friends within my app delegate, but if I put the code in the same place in TokenCacheHowTo it outputs Found: X friends where X is my actual number of friends. This is confusing to me because I am able to get the users information such as their id and name from Facebook and store it on my server.
I realize that there is probably a simple solution to this but I don't have a good grasp of the Facebook SDK yet and I'm stuck.
Try this as working fine for me and Ensure about the Permissions like
NSArray *array = [NSArray arrayWithObjects:#"user_friends", nil];
and then fetch all the friend
-(void)getFriendList {
FBRequest* friendsRequest = [FBRequest requestWithGraphPath:#"me?fields=friends.fields(first_name,last_name)" parameters:nil HTTPMethod:#"GET"];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSDictionary* friendsDic = [result objectForKey:#"friends"];
NSArray *friends = [friendsDic objectForKey:#"data"];
for (NSDictionary *friend in friends) {
NSLog(#"firstname %#",friend[#"first_name"]);
NSLog(#"last name %#",friend[#"last_name"]);
}
}];
}
Nothing wrong with your code. I've used the same code which you used above and I got x friends list. But my permission is declared as below
FBSession.activeSession = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:#"user_about_me", #"email",#"user_birthday", nil]];
Note: I want email id and birthday from users that why my permissions include that fields. And It should be declared before authentication, then only sessions kept this permission as it is.

How to post on Facebook Page using graph api

We are using Facebook graph api to share videos on facebook, when user share Facebook video on his wall at same time we are sharing same video on Facebook App page.
Following is the code we have used to share video on App page,
NSDictionary *videoObject = #{
#"title": self.videoDetails.videoTitle,
#"contentType": #"video/quicktime",
#"description": [NSString stringWithFormat:#"%# %#",self.videoDetails.videoDescription,tag],
[pathURL absoluteString]: videoData
};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:[NSString stringWithFormat:#"%#/videos",kPage_ID]
parameters:videoObject
HTTPMethod:#"POST"];
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
So as we post video on user wall we use "me/videos" and if we want to post on page i am using "page_id/videos", and it was working fine but recently something has changed and now its not allowing to post on app page, giving error.
error = {
code = 200;
message = "(#200) App does not have permission to post to target";
type = OAuthException;
};
Is anyone faced same issue recently.

Resources