How to post on Facebook Page using graph api - ios

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.

Related

FB Graph Subscription IOS send access_token

There is something to the Facebook Graph SDK (and its iOS implementation) that really makes my life miserable. And it seems I'm on my own, because I don't seem to be able to find anyone on the 'net with a similar problem/lack of understanding like me.
Without further ado:
I have this code in my iOS app, that is supposed to subscribe my app to user updates:
-(void)subscribeToFacebook{
(FBSession.activeSession.isOpen) ? NSLog(#"is open") : NSLog(#"is closed");
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
#"page", #"object",
#"http://www.example.com/fbcallback.php", #"callback_url",
#"about, picture", #"fields",
#"ItsMeAlright", #"verify_token",
nil
];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/app/subscriptions"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
NSLog(#"error= %#",error);
}];
}
When I run this code, an error is logged, stating:
"(#15) This method must be called with an app access_token."
Now, I (think) I know how to get the access_token
NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];
but I have't got a clue on where and when to send it to Facebook.
I tried to append it to the #"/app/subscriptions" part like this
NSString *urlString = [NSString
stringWithFormat:#"/app/subscriptions?access_token=%#",
[fbAccessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
but that didn't work.
Your input is extremely welcome!
The way to do this will be to create a FBSession with the application token. Because the current session isn't what you want.
https://developers.facebook.com/docs/reference/ios/current/class/FBSessionTokenCachingStrategy
https://developers.facebook.com/docs/facebook-login/ios#sessions
But, security wise, you shouldn't be doing this at all. It's very insecure to embed your application token in a production application. I believe that the iOS sample generated for you is incorrect.
You should be sending any request that requires the application token with a server call (e.g. PHP)

How to Post image on FB Users wall with the message ?(without using URL for image)

I am trying to post on users wall using ios app by using FB New graph API 3.17.1.But when I post using the graph path me/photos, it will create an bunch of post at one location instead of posting the images as separate story.
I did lot of R&D and found this Post photo on user's wall using Facebook iOS SDK
I used below method to post on user's wall
NSMutableDictionary* postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"<Image URL>", #"picture",
#"Facebook SDK for iOS", #"name",
#"build apps.", #"caption",
#"testing for my app.", #"description",
nil];
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result,NSError *error)
{
if (error)
{
NSLog(#"Error in uploading the photo %#",error);
}
}];
This method does paste the image on user's wall but for this image has to be uploaded somewhere on internet and we have supply the URL of same.And additionally it makes image visibility very less compared to image posted using me/potos.
[FBRequestConnection startWithGraphPath:#"me/photos" parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection*connection, id result, NSError *error)
{
NSLog(#"Error : %#",error);
NSLog(#"%#",result);
}];
I used above method but it will group the photos into bunch and make the album on the users wall after 3-4 post. And additionally it has limitation of max 25 post per app per day. So this method is negligible.
Please let me know any alternative way, if anyone has used.I would be very thankful.

Opening facebook app through another app

Hi I am trying to open the Facebook app when users click a button within my app. What I have done is link the users to their Facebook profile so that I can capture their user ID. Then I am querying their ID and trying to pass it through to a button on their "profile". Unfortunately this isn't working on my simulator. I'm not sure if it is because the simulator doesn't have the Facebook app, or because there is a flaw within the syntax. Could someone please shed some light on this for me. I was wondering how you could open Facebook profile in the Facebook app with the click of a button. In my sign up page I have user's link their Facebook account, and in the button I retrieve the Facebook id and link it to the Facebook app URL. It doesn't run in the simulator, but this could be that it isn't hooked up to the Facebook app maybe? Is there anything wrong with my code?
- (IBAction)fbProfile:(id)sender {
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSDictionary *userData = (NSDictionary *)result;
NSString *facebookID = userData[#"id"];
NSMutableString *fbProfile = [NSMutableString stringWithString:#"fb://profile/"];
[fbProfile appendString:facebookID];
NSURL *profileURL = [[NSURL alloc] initWithString:fbProfile];
[[UIApplication sharedApplication] openURL: profileURL];
}
}];
}
This cannot work on the simulator because it does not have the Facebook app installed and hence does not have the Facebook URL handler registered. Try it on a device.

Sharing to Facebook Wall

I am using facebook sdk and need to share details to facebook timeline. I am using the following api call.
[FBRequestConnection startWithGraphPath:#"/feed"
parameters:dictionary
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (!error) {
[VBUtility showAlertWithTitle:#"Facebook" message:#"Deal details posted successfully"];
}
}];
The story is published on facebook, not at user's timeline but user's newsfeed (The document tells this method does - posts and links published by this person or others on their profile.). I have also tried with /home method call. While I tried with the built in facebook share,
SLComposeViewController *fbPost = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
it is perfectly published to user's timeline as well as in news feed. I have configured the app in the developer.facebook.com. Do I need to mention any permissions here. Does any one can help me finding the mistake?
Permission Request,
NSArray *permissions = [[NSArray alloc]initWithObjects:#"publish_actions",#"user_birthday",#"publish_stream",#"user_about_me",#"email",#"basic_info",nil];
The parameters passed are,
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
app_id, #"app_id",
name,#"name",
caption, #"caption",
description,#"description",
link, #"link",
picture, #"picture",
#"1",#"fb:explicitly_shared",
nil];
Try this,
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:dictionary
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (!error) {
[VBUtility showAlertWithTitle:#"Facebook" message:#"Deal details posted successfully"];
}
}];
I changed little bit from your code. Change your path as #"me/feed". I hope, this may help you.

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

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.

Resources