How to post image to friend's Facebook wall - ios

NSData* imageData = UIImageJPEGRepresentation(self.qqqimage, 90);
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.messegeSend.text, #"message",
imageData, #"source",
nil];
postPath = [postPath stringByAppendingFormat:#"%#/feed",[friendList objectAtIndex:i]] ;
[FBRequestConnection startWithGraphPath:postPath
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
This is my code , but get error http 200
I also try postPath with #"%#/photos",friendID , but http 200 again

Related

How to post on Facebook page as Page Post from app via graph API in iOS?

I am trying to post on Facebook page as a page post. I using am below graph code API, but post coming on side as other people post, not as page admin/Page itself:
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Testing Post", #"name",
#"This is testing", #"message",
#"this is description", #"description",
nil];
NSString *feed = [NSString stringWithFormat:#"/Page ID/feed"];
[FBRequestConnection startWithGraphPath:feed
parameters:params
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
if(!error){
NSLog(#"%#", result);
}
else{
NSLog(#"Error %#", error);
}
}];
If you want to post as the Page itself, you'll need to use a Page Access Token with the publish_pages permission.
See
https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed#publish
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
Here is Complete Answer
NSString *accesstoken = <Page_Access_Token>
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Post heading", #"name",
accesstoken, #"access_token",
#"Type post message", #"message",
#"Hyperlink to your post", #"link",
#"Add description", #"description",
#"Image url string", #"picture",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error) {
NSLog(#" %#", result);
}
else
{
NSLog(#"%#", error);
}
}];

How to post status feed on Facebook page as pageadmin in iOS?

I want to post status on my Facebook page. Status should be shown on Facebook as a page status not status from any username or from my name.
I tried below code,
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:#"This is a check for page post message", #"message", nil];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/1521177224766299/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error){
if (result)
{
NSLog(#"Result %#", result);
}
else
{
NSLog(#"%#", error);
}
}];
a message status was posted done page wall but that status come from my name.
But when I tried to hit same post method with page_id/feed POST Query and with same parameter #"this is my status" #"message" from graph api explorer page, it posted status from page not from me.
Please help.
NSString *accesstoken=[NSString stringWithFormat:#"%#","here add your page access_token"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
accesstoken, #"access_token",
postingString, #"message",
// #"http://www.real-timesports.com", #"link",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
NSLog(#"requestToPost==%#",requestToPost);
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"facebook result >> %#", result);
}];
[requestToPostConnection start];
Here is Complete Answer
NSString *accesstoken = <Facebook_Page_Access_Token>
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Post heading", #"name",
accesstoken, #"access_token",
#"Type post message", #"message",
#"Hyperlink to your post", #"link",
#"Add description", #"description",
#"Image url string", #"picture",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error) {
NSLog(#" %#", result);
}
else
{
NSLog(#"%#", error);
}
}];

formatting a url to appear as string in a facebook post

I am trying to post a link formatted as a string on facebook. Please see the relevant code below:
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
NSString *modifiedTitle = [NSString stringWithFormat:#"<a href= https://www.google.com> My App </a>"];
[params setObject:modifiedTitle forKey:#"message"];
[params setObject:UIImagePNGRepresentation(picture) forKey:#"picture"];
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
if (error)
{
//showing an alert for failure
NSLog(#"ERROR in posting image to Facebook");
}
else
{
//showing an alert for success
NSLog(#"Result after posting image successfully = %#",result);
}
// button.enabled = YES;
}];
The message appeared as:
<a href= https://www.google.com> My App </a>
instead of
My App
For one thing, ensure you're posting an immmutable dictionary into the startWithGraph... method by using the copy method:
NSDictionary* paramsImmutable = params.copy;
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:paramsImmutable
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
That way you won't have any changes to worry about on that object during the method's lifetime.
Next, is your params including any sort of quotes around the url? I.e.
NSString *modifiedTitle = #"<a href='https://www.google.com'>My App</a>";
That's just a start.

Building Facebook IOS friend multi-selector

I want to build a friend multiselector so that my user can send a request to anyone of his friends. I know that there is the FBfriendselectorcontroller, but it does not have the option to select all friends, and I would like to have it in my app. I tried to populate a UITableview manually by getting the friend list in this way:
permissions (logged in using the log-in button):
NSArray *permissions = [[NSArray alloc] initWithObjects:#"public_profile", #"email", #"user_friends", nil];
self.loginView.readPermissions = permissions;
data:
[FBRequestConnection startWithGraphPath:#"me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
//NSArray *data = [result objectForKey:#"data"];
NSLog(#"%#", result);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:#"%#", result], #"to", #"send", #"action_type", #"YOUR_OBJECT_ID", #"object_id", nil];
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Take this bomb to blast your way to victory!"
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {}
];
}];
the friend count returns 318, but the "data" is like this: (). I also tried the:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error){
NSArray* friends = [result objectForKey:#"data"];
but the data is null. What am I doing wrong??!!

How to get large picture size from Facebook graph API for news feed

I am stuck with getting picture from Facebook Graph API for news feed with small size. This is the url I get https://fbcdn-photos-b-a.akamaihd.net/hphotos-ak-xpf1/t1.0-0/10363492_10202184985725870_7374705736674502849_s.jpg. Not sure how will get the picture with size o.jpg
Finally, figured it out. Here is what I did.
NSString *query = [NSString stringWithFormat:#"SELECT pid, object_id, src_big, src_big_width, src_big_height FROM photo WHERE object_id = %#", wallPost[#"object_id"]]; //begins from SELECT........
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
query, #"q",
nil];
[FBRequestConnection startWithGraphPath:#"/fql" parameters:params HTTPMethod:#"GET" completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
//do your stuff
if (!error) {
NSArray *photo = [result objectForKey:#"data"];
NSString *photoString = [[photo valueForKey:#"src_big"]componentsJoinedByString:#""];
//NSLog(#"result %# %#", photoString);
}
}];

Resources