Can FBRequestConnection startForCustomAudienceThirdPartyID be used on its own? - ios

I want to get the app user ID for Facebook, as described here:
https://developers.facebook.com/docs/ads-for-apps/custom-audiences-for-mobile-apps/
The code snippet they give is:
[FBRequestConnection startForCustomAudienceThirdPartyID:nil
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *id = error ? nil : [result objectForKey:#"custom_audience_third_party_id"];
// Stash off this id, send it to your server, etc. Use later to construct
// a custom audience. A result of 'nil' means that either the user can't be
// identified, or they've limited ad tracking via iOS 6.
}
];
This always returns error 400 for me. Answers like this suggest that it needs to be used as part of a larger piece of code but there's no mention of this on the Facebook page.
Can I just use the snippet above, or do I need to implement something around it?

I got this from the FB developer page:
Discussion:
This method will thrown an exception if either <[FBSettings defaultAppID]> or <[FBSettings clientToken]> are nil. The appID won't be nil when the pList includes the appID, or if it's explicitly set. The clientToken needs to be set via <[FBSettings setClientToken:]>.
.....
Please check the conditions above first. Ass per documentation
startForCustomAudienceThirdPartyID: -> should actually point to the current FBSession

Right after the session is created do this: [FBSession setActiveSession:session];
Answered here: Facebook iOS SDK 3.1: "Error: HTTP status code: 400"

Related

Fetch Facebook Posts for Public Page using Facebook SDK

I'm trying to fetch Facebook posts for a public page using the Facebook SDK for iOS. I can't seem to figure out how to get and then use the access token I need to make this request. Let's say it's the New York Times page. This shouldn't require any permissions, so I should be able to use the App Access Token...but again, I can't figure out how to get & use that.
The code I am using looks like this:
[FBRequestConnection startWithGraphPath:#"/nytimes/posts" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"DATA: %#", [result data]);
NSLog(#"ERROR: %#", error);
}];
I keep receiving an error saying that an access token is required.
Please help!
It means it asking you a permission to access the public post in view did load method put one line code like (readPermissions = #[#"public_profile", #"email",#"user_friends",#"user_likes",#"user_groups"];)
, for more details see this https://developers.facebook.com/docs/facebook-login/permissions/v2.2.

Getting the user’s Facebook list of friends

After being able to create a small iOS app that logs in to Facebook. I would like this app to get the user’s list of friends.
Though I browsed the internet for a while and tried various approach I did not succeed to get what I wanted.
In the viewDidLoad method I use this code to start with:
loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"user_friends"]];
And then I implement the loginViewFetchedUserInfo: user: method this way:
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#“Result: %#",result);
}];
}
When I execute the app I get this result:
Result: {
data = (
);
summary = {
"total_count" = 267;
}; }
But what I really want is a list of the friends with their names …etc…
All the things I tried for that didn’t work. Though I suppose the solution must be simple.
I also used code like this in the method above ….. but with no luck:
NSArray* friends = [result objectForKey:#"data"];
One more point, here https://developers.facebook.com/docs/graph-api/reference/v2.1/user/friends one can read:
This will only return any friends who have used (via Facebook Login)
the app making the request.
But the result I get (267) does not match this statement. It (267) is the number of friends the user has on Facebook, which is in fact what I am interested in.
I hope someone has something to say to put me on the right track and make things clearer.
Since Facebook's 2.x SDK upgrade they have tightened up access to information in the "Open Graph API."
Under Permissions That Do Not Require Review
App friends. This optional permission grants your app the ability to read a list of friends who also use your app.
You get automatic access to any friends that already use your app (per its Facebook ID.)
You will have to request Extended Permissions if you want to access the list of all a user's friends. That means going through Facebook's App Review process which can be quite challenging (and annoying.)
Frankly, I am not even sure that it is possible to use the new Open Graph API to get the user's entire friend list.

Facebook Like/Unlike gives error message

I am building an application which implements Facebook. Through this application I can like and comment on a post. I am fetching Home feeds for the logged in user. Now for Like operation I am using the graph API :
https://graph.facebook.com/POST_ID/likes?&access_token=ACCESS_TOKEN
with HTTPMethod: POST
Here, the POST_ID is the ID I am getting for each feed and the access token of the logged in user.
Now in most of the cases I can like the feed using this API. But some posts don't have Like Connections. How do I know which feed has a like connection & which does not.
Now coming to Unlike. For Unlike operation I am using the graph API :
https://graph.facebook.com/POST_ID/likes?&access_token=ACCESS_TOKEN
with HTTPMethod: DELETE
I can unlike some posts or feeds using this API. But for some I get an error message. In that case i am using for example:
This is the
POST_ID = 12345_67890. When I get error message for this I am using the 67890 as the POST_ID in this case & I am getting success to unlike a post/feed.
Again in using this 67890 as POST_ID gives error in some cases & in that case I am using OBJECT_ID if exists in the feed I am receiving. And I am getting true response in some cases.
But in rest of the cases I can't find any solution for Like & Unlike of a feed/post in Facebook.
Waiting for positive reply.
if you are using correct post_id of feed than it will never produce any error while liking/disliking post on facebook by following code
if do you want to like than change HTTPMethod to POST otherwise set DELETE for dislike. there is no need of accesstoken to call this api.if you are using so it will not produce any error
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/likes",#"Post_id"] parameters:nil HTTPMethod:#"DELETE" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
{
NSLog(#"error: %#", error.localizedDescription);
}
else
{
NSLog(#"ok!! %#",result);
}
}];

"Could not generate preview text" error when creating object with Open Graph action

I'm using the iOS SDK with the native dialog to try to post an object and action.
When I call presentShareDialogWithOpenGraphAction, the Facebook app opens, briefly shows the dialog with my post in it, and then returns to my app with the error:
Could not generate preview text
My code looks like this:
NSDictionary* object = #{
#"fbsdk:create_object": #YES,
#"type": #"appsterbator.app_idea",
#"title": #"test",
#"url": #"http://test.com",
};
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:object
forKey:#"app_idea"];
[FBDialogs presentShareDialogWithOpenGraphAction:action actionType:#"app_idea.create"
previewPropertyName:#"app_idea"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
NSLog(#"%#", error);
}];
Also, is it possible post an Open Graph object that doesn't actually have a URL?
I had the same symptoms, but a different fix. Facebook SDK 3.5.* since the Share Dialog came out of beta.
I had a custom Object Graph story: Solve -> Puzzle. This was my first time working with OG, so this might seem obvious to someone more familiar with it, but it stalled me for long enough that I wanted to share.
I ran through the Share Dialog examples on the developer site, but the Open Graph related sharing would not work via simple copy paste. I figured because the OG objects were tied to the App ID and URL host etc. I setup my web host so that I could serve OG data for my objects, and configured my app to allow that host etc..
So I set about adapting the sample code to use the parameters present in the "opengraph / stories -> Get Code" popover. Setting the platform to iOS SDK, I got the following for Create Action:
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"puzzle"] = #"http://samples.ogp.me/463417983744195";
[FBRequestConnection startForPostWithGraphPath:#"me/shapeshuffle:solve"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
// handle the result
}];
I swapped my story and app specific values into the sample code, leading to the the error and symptoms described in the question.
I spent longer than I care to admit fiddling with the server hosting my OG object, FB App settings, different ways of popping the share dialog etc.
The root of the problem was that on popping the dialog, FB was unable to match the action and object with the configuration in my app - hence the slightly vague error code relating to generating the preview text. FB wasn't finding the action because "me/shapeshuffle:solve" (the action string in the "Get Code" tool) doesn't resolve. If I understood all the different options available to me in the Get Code tool, I might have avoided this, but remember, all I wanted was to pop a share dialog. Seemed simple.
I worked with the Graph API explorer via this useful tutorial, and wound up with the following mapping from the strings I got from the FB tool to what actually worked:
Action:
me/shapeshuffle:solve => shapeshuffle:solve
Lots of pain for 3 little characters. Here is what my finished code looks like:
NSString *objectUrl = [NSString stringWithFormat:#"%#puzzleId=%d", #"http://myhost.com/puzzle/object?", puzzleId];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectUrl forKey:#"puzzle"];
[action setObject:timeString forKey:#"time"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"shapeshuffle:solve"
previewPropertyName:#"puzzle"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
Had the same issue. Make sure the App Domains in Basic Info contains the oAuth domain. The odd thing I found is that in order to add this you need to enable this can only be added if you enable Page Tab or Mobile Web or one of the other options.
I think i may know the reason that (#"url": #"http://test.com")->this may use the facebook app developer center offer.
click Open Graph
click Stories
then you will see your custom story on right side
click Get Code,then you will get the URL you need!
and (#"type": #"appsterbator.app_idea")->this may need use like this->(your_app_namespace:action_type)
Good luck!
To problem with: "Could not generate preview text" come from attempts to share the same content several times.
Try to change content that you share each time you check the functionality of open graph.
A condition that causes this which has not been described yet is case sensitivity of the action and property name, which must be lowercase. To illustrate note the 'must_be_lowercase' in the following:
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:#"http://link/" forKey:#"**must_be_lowercase**"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"xxxx"
previewPropertyName:#"**must_be_lowercase**"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
This is a lovely generic error message! Another possible cause I've encountered is the size of the OpenGraph image being posted.
Although Facebook documentation states images must be 200x200px to 1500x1500px, my initial attempts with a 350x350px image failed with the “Could not generate preview text” error. The same image at 600x600px on the other hand works perfectly.
-James

Facebook Profile Picture Large

I am having trouble trying to request the large version of the users profile picture on Facebook.. in my graph path I'm doing:
NSString *requestPath = #"me/?fields=first_name,last_name,gender,email,birthday,verified,picture";
The picture field in there only gives me the small version of the profile picture, but i need the large and the normal version.. i already tried changing picture to picture_large, pic_large, image_large but none of this works..
Please, i already read the documentations, so don't bother answering if you plan on telling me to read it again.. I'm asking this here because i already searched everywhere and couldn't find a solution.
Thanks,
Newton
The short answer you are looking for is picture.type(large)
I was looking for the same thing and found the answer using Facebook Graph API explorer found here.
Now if I use the following code:
[FBRequestConnection startWithGraphPath:#"me"
parameters:[NSDictionary dictionaryWithObject:#"picture.type(large),id,email,name,username"
forKey:#"fields"]
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error){[self fbRequestCompleted:result];}];
the "picture" key in the "result" dictionary has the value of the large picture's URL.
You can just use:
http://graph.facebook.com/USER/picture?type=large
Where USER can be either the user id or the user name.
That returns a redirect to the static image url, as written in the User object documentation:
HTTP 302 redirect to URL of the user's profile picture (use
?type=square | small | normal | large to request a different photo).
Nitzan Tomer's response is still correct for iOS; if you want to get the large version of the user's profile picture using Facebook's iOS API, you can just write:
[facebook requestWithGraphPath:#"me/picture" andParams:[NSMutableDictionary dictionaryWithObject:#"large" forKey:#"type"] andDelegate:self];
And you will get the image data in the result object, in this delegate method:
- (void)request:(FBRequest*)request didLoad:(id)result

Resources