how to post facebook fan page wall - ios

I tried to post image in facebook fan page.
I am using below code:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/facebookPage_ID/photos"
parameters:#{ #"url": #"https://dncache-mauganscorp.netdna-ssl.com/thumbseg/378/378006-bigthumbnail.jpg",}
HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
// Insert your code here
}];
Current image posts to facebook page successfully but image "did not post in facebook page wall" is shown in visitor post.
I want to show image in facebook page wall.

You need to use a Page Access Token instead of a User Access Token:
https://developers.facebook.com/docs/facebook-login/access-tokens/
http://www.devils-heaven.com/facebook-access-tokens/
The steps:
Get a User Token with the manage_pages and publish_pages permissions
Use /page-id?fields=access_token to get a Page Token for a specific Page

Related

how to get the facebook post details from share url in iOS

I have a facebook share url like this (https://www.facebook.com/pus18/videos/498575787191356/). From the share url i want to get details like post id, title, source, length of the video. Please give suggestions if possible please provide the code to get the details of the post in iOS.
Thank you
First of all try to take a look at Facebook guide that is connected with posts.
From this guide it is easy to get information that you are searching for.
Objective-c style.
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/{post-id}"
parameters:params
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
}];

Get USER tagged and saved videos by graph api

I have two queries;
1- How can i get user's tagged videos as the below request to Graph API returns me nil on request :( and i have spend about thousands of minutes on searching for this issue but did not find the accurate answer or reason of this issue.
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/videos/tagged"
parameters:nil
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
// Insert your code here
NSLog(#"Result is:%#",result);
}];
2- How to make a call for user's saved videos on Facebook to Graph API?
I am Running FB SDK Version 4.20.2 and Graph API version 2.9.
Currently I am using a test account for this purpose and all videos are public.

How to include limit for retrieving page likes by current user by using FB SDK

I had a little problem about how can I set the limit when requesting page likes by current user using FB SDK for iOS. Whenever I tried the request it returns 25 result of FB pages instead of limit it by one.
this is my code for requesting FB page likes by current user :
http://i.imgur.com/LdkgaYU.png
I think my code is correct, because I tried it before in FB Graph Explorer tools, it's working perfect. Here is what I did in FB Graph Explorer :
http://i.imgur.com/YX0SpHD.png
Anyone have any idea how can I fix this little problem? Thank you in advance.
Try this you may be helped
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/me/likes"
parameters:#{ #"fields": #"about,name,created_time",#"limit": #"1",}
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
// here you got a one result from this code
NSLOG("%#",result);
}];

Get the relationship status of user's Facebook friends

This is what I'm using now:
if ([FBSDKAccessToken currentAccessToken]) {
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/me?fields=id,name,friends{relationship_status}"
parameters:nil
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"Result: %#", result);
}];
}
but the result contains an empty list of friends. I guess this list contains the friends that have installed this same app.
Using the Graph Tool Explorer I can get this list
GET /v2.3/me?fields=id,name,friends{relationship_status,gender}
How can I get this list in iOS?
Permissions that I'm calling are:
loginButton.readPermissions = #[#"public_profile", #"email", #"user_friends"];
***** UPDATE *****
Ok, I've read the confirmation: "Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app."
Has anyone used taggable_friends or something like that to get the list of friends making more requests later to get the information about each and every friend? Is this something Facebook can reject when submitting the app?
That's not possible, because all friends_* permissions have been removed. Please don't waste your time trying to find a workaround.
See
https://developers.facebook.com/docs/apps/changelog#v2_0
All friends_* permissions have been removed.

Facebook iOS SDK posting as a Page

In my iOS app, I want to post on a Facebook Page as the Facebook Page.
I retrieve the page access tokens through the 'me/accounts' endpoint through the user. However, I am not sure how to create an FBSession using that page access token in order to create the post request.
The page access token is a string, and I obtained it correctly by asking the user for 'manage_pages' and 'publish_streams' permissions.
Is there an easy way to do this? I have been looking at the fetchFBAccessTokenData but am not sure how I could use it.
The answer is - and this took me a long time to find - initWithSession:FBSession.activeSession should be initWithSession:nil, and the access token should be set direction in the parameters NSDictionary field as [parameters setObject:yourAccessToken forKey:#"access_token"]. The access token in the FBSession.activeSession overrides the access_token in the parameters (which it shouldn't IMHO), making the post appear as a "fan" post, instead of a post as the page.
[d addObject:yourFetchedAccessTokenString forKey:#"access_token"];
FBRequest *request = [[FBRequest alloc] initWithSession:nil
graphPath:graphPath
parameters:d
HTTPMethod:#"POST"];
Of course now there are other issues, such as how long the access token will last, which requires token caching stategies: https://developers.facebook.com/docs/howtos/token-caching-ios-sdk/
Found answer here: https://github.com/facebook/facebook-ios-sdk/pull/483
Thousand thanks for James O'Brien's Code. In addition to that,
you may need the below code:
FBRequestConnection *con = [[FBRequestConnection alloc] init];
[con addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error){
NSLog(#"facebook result >> %#", result);
[self cancelfbshare:nil];
}];
[con start];

Resources