Facebook friend's wall posting through ID - ios

I am trying to post on a Facebook friend's wall, I tried these two methods but none work:
1.
//post on wall
NSMutableDictionary *variables = [[NSMutableDictionary alloc]initWithCapacity:1];
[variables setObject:#"v" forKey:#"message"];
[graphref doGraphPost:[NSString stringWithFormat:#"1389799421/feed"] withPostVars:variables];
//post on wall
2.
[_facebook requestWithGraphPath:#"1389799421/feed"
andParams:[NSMutableDictionary dictionaryWithObject:#"test wall post" forKey:#"message"]
andHttpMethod:#"POST"
andDelegate:self];
...and I can't understand why!! On the facebook website I have added the bundle and the permissions.

I am trying to post on a Facebook friend's wall
Facebook recently announced in the developer blog, that posting to another user’s wall through the API will not be possible any more from Feb 2013 on:
Removing ability to post to friends walls via Graph API
We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog.
So I think it’s pretty useless starting to develop a feature like that now.

First off, you have to open your session with publish permissions. Specifically, you must request the publish_stream permission.
NSArray * permissions = [[NSArray alloc] initWithObjects:#"publish_stream", nil];
return [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session
state:status
error:error];
}];
If you have publish permissions, you can create and send the request. Make sure you include the access_token as one of the parameters. If you don't, you will get authentication errors.
NSDictionary * postParameters = [NSDictionary dictionaryWithObjectsAndKeys:_textView.text, #"message", FBSession.activeSession.accessToken, #"access_token", nil];
NSString * graphPath = #"ID_NUMBER_HERE/feed";
FBRequest * request = [FBRequest requestWithGraphPath:graphPath parameters:postParameters HTTPMethod:#"POST"];
[[request initWithSession:FBSession.activeSession graphPath:graphPath parameters:postParameters HTTPMethod:#"POST"] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"Successful posted to Facebook");
}];
}

Related

Facebook Graph Api v2.0 me/photos returns empty for all users except me who created the app

I am using this code below, which uses the parse sdk:
[PFFacebookUtils initializeFacebook];
[FBSession.activeSession requestNewReadPermissions:#[#"user_photos"] completionHandler:^(FBSession *session, NSError *error) {
if (!error) {FBRequestConnection *connection = [[FBRequestConnection alloc] init];
FBRequest *request = [[FBRequest alloc] initWithSession:[FBSession activeSession]
graphPath:[NSString stringWithFormat:#"me/photos"]];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {}];
[connection start];
This all works fine for me it downloads all the most recent photos. But for anyone else, who has logged in via Facebook on the app the result returns:
{
data = (
)
}
Why am i, the developer, the only one who is able to access his photos? Is there a setting in the app settings on Facebook?
From v2.0 onwards, the permissions other than public_profile, email and the user_friends need to the submitted for review before you can make your app live; until then, only the testers/admin/developers of the app will be able to test app with those permissions.
See here for details on the Login Review.
yes there is,
You have to go on you facebook developer account -> go on the application -> add a contact email.
After that go to status & review -> and set Do you want to make this app and all its live features available to the general public? to yes.
Now it should work

ObjC, Facebook Page - posting news feed works, but posting photo does not

so I'm trying to post a photo on my Facebook page (I'm admin) from iPhone app. I'm using FB Sessions to create the session, get the read permission, get manage_pages permission, then, I successfully get my Facebook Pages app-ids as a result of
[FBRequestConnection startWithGraphPath:#"/me/accounts" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"%#", [result description]);
}]; // have token, what now?
Which is still fine. Then, I try to post a photo to the app_id/photos feed, and it does not work = it uploads the photo correctly, but shows me (as in my profile) uploading the photo rather then the Page itself. What could be the problem?
Here's the code for the params and the call
NSDictionary *params = [NSDictionary
dictionaryWithObjects: [NSArray arrayWithObjects:
[UIImage imageNamed:#"Icon.png"],
#"This is my first photo post from xcode app", nil]
forKeys:[NSArray arrayWithObjects:
#"source",
#"message", nil]];
[FBRequestConnection startWithGraphPath:#"MyPageID/photos" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"%#", [result description]);
} ];
the [result description] log from the call is fine (it returns the id = xx and "post_id" = yy, which I assume are correct), as is the call itself - the only problem is that it shows me as the author, and not the Page itself.
MyPageID is correct, because calling
NSDictionary *paramsFeed = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:#"This is my first page post from xcode app", nil] forKeys:[NSArray arrayWithObjects:#"message", nil]];
[FBRequestConnection startWithGraphPath:#"390106241058188/feed" parameters:paramsFeed HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"result: %#", [result description]);
}];
Also, calling me/photos and posting the photo there with dictionaryKey #"picture" works, and it posts the photo on my own wall perfectly.
Do anyone knows where the problem could be hidden?
I found the solution, although I find it weird that I did not have to do this for the /feed page update
Huge thanks goes for Mr. Arpit Kumar Kulshrestha, who pointed out the right way in my previous incarnation of the problem ( Xcode - how to share photo from iPhone app to Facebook managed page feed )
the solution:
I've tried setting a new FBSession before, but it still had a lot of errors in it, so I've left that route and went to another one. However, it makes perfect sense to do that -
create FBAccessTokenData, which has the Page's token in it, and set other things to the same as the active session - like this
FBAccessTokenData *tokenData = [FBAccessTokenData createTokenFromString:pageTokenString permissions:[FBSession activeSession].accessTokenData.permissions expirationDate:[FBSession activeSession].accessTokenData.expirationDate loginType:FBSessionLoginTypeFacebookApplication refreshDate:nil];
then, one need to create a new FBSession, and what is important, it needs to have set its tokenCacheStrategy to something without data, i.e.[FBSessionTokenCachingStrategy nullCacheInstance] . I did a blank allocation ([[FBSession alloc] init]), and that gave me a lot of errors, however when I use this one
FBSession *sessionFb = [[FBSession alloc] initWithAppID:appID permissions:[NSArray arrayWithObjects: #"publish_stream", #"manage_pages", nil] urlSchemeSuffix:nil tokenCacheStrategy:[FBSessionTokenCachingStrategy nullCacheInstance]];
it works perfectly. And when you have this new session, you want to open the path for the data to come and go, and you can make it like this:
[sessionFb openFromAccessTokenData:tokenData completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
{
}];
and the last part before it starts working correctly is setting the activeSession to this newly allocated and opened session, this way:
[FBSession setActiveSession:sessionFb];
after I've made all of these changes, the photo page sharing started to work magically.
However, I'm still not sure how is it possible that the photo share did not work before but the feed share did.. but this solves my issue.

Sharing Video to facebook via FB SDK for iOS

I have a video created in my app.
I want to shared this video to user's Facebook wall via facebook native SDK.
I am able to get the video sharing working, but there is no preview/share dialog shown to the user before sharing. The video is directly posted to user's wall.
Here is my code to get open an active session
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceOnlyMe allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error){}
Once I get the session active, I call the below method to share the video
- (void)sendVideoFeedRequestWithParams:(NSMutableDictionary *)params
{
// create the connection object
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
// create a handler block to handle the results of the request
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection result:result error:error];
};
// create the request object, using the /me as the graph path
FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:#"me/videos" parameters:params HTTPMethod:#"POST"];
// add the request to the connection object, if more than one request is added
// the connection object will compose the requests as a batch request; whether or
// not the request is a batch or a singleton, the handler behavior is the same,
// allowing the application to be dynamic in regards to whether a single or multiple
// requests are occuring
[newConnection addRequest:request completionHandler:handler];
// if there's an outstanding connection, just cancel
[self.requestConnection cancel];
// keep track of our connection, and start it
self.requestConnection = newConnection;
[newConnection start];
}
The params I am sending to this method are:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, #"video.mov",
#"video/quicktime", #"contentType",
#"Video Test Title", #"title",
#"Video Test Description", #"description",
nil];
This works well as far as posting the video is concerned. But, I want a share/preview dialog to be shown.
Anybody got any hints on how to get it done?
You need to create something yourself or search for an existing solution on github (or similar). Something like a custom alert view where you can allow the user to enter text, have a thumbnail of the video which plays when tapped and a couple of buttons.

I Only Get Facebook Active Access Token When Using iOS Facebook Integration

So when I am logged in to ios's facebook integration, my code works great. I get an active access token with permissions to read and write, and I have actually written to people's walls and whatnot from the app. However, when my app uses safari to authenticate people's login credentials, there is the common error: "An active access token must be used to query information about the current user."
What I don't understand is why I can only get my access code from the ios facebook integration. Anyways, my relevant code below is implemented by the current view controller when it loads:
if (![FBSession activeSession].isOpen) {
[self openSession];
}
my method openSession is defined as follows
- (void)openSession
{
//create the permissions array
NSArray *permissions =
[NSArray arrayWithObjects:#"email", #"basic_info", nil];
[FBSession openActiveSessionWithReadPermissions: permissions
allowLoginUI:YES
completionHandler: ^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(#"\n\nopenSession called error = %#\n\n\n",error);
}];
}
I then go on to continue in the viewDidLoadMethod
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error)
{
NSLog(#"error requestion connection: %#",error);
}];
I look forward to the response. Thanks in advance.
Using Facebook SDK.
NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];
If you prefer dot syntax,
NSString *fbAccessToken = [FBSession activeSession].accessTokenData.accessToken;`
I hope , it will work for u

iPhone - How to post image on friend's facebook wall

if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound)
{
// No permissions found in session, ask for it
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
// If permissions granted, publish the story
if (!error)
{
[self postImageToFB] ;
}
}];
}
// If permissions present, publish the story
else
{
[self postImageToFB] ;
}
- (void) postImageToFB
{
NSData* imageData = UIImageJPEGRepresentation(self.image, 90);
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"test", #"message",
imageData, #"source",
nil];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/photos",friendName]
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"%#",error) ;
if( error == NULL )
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:#"Post sucessed!!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] ;
[alert show] ;
}
}];
}
I can use - (void) postImageToFB function to post on my own wall when I change [NSString stringWithFormat:#"%#/photos",friendName] to #"me/photos"
But I can't post on my friend's wall , maybe permission is wrong or there are some problem I didn't know ?
I got these error
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xc0a7320 {com.facebook.sdk:ErrorInnerErrorKey=Error
Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xc001ea0 {NSUnderlyingError=0xaa45270 "bad URL", NSLocalizedDescription=bad URL}, com.facebook.sdk:HTTPStatusCode=200}
You cant Post to friends wall from now...
Removing ability to post to friends walls via Graph API We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag). For more info, see this blog post.
Check this...changes mentioned at facebook developers portal
https://developers.facebook.com/roadmap/completed-changes/#february-2013
From the Link #viswa posted we can read
Removing ability to post to friends walls via Graph API We will
remove the ability to post to a user's friends' walls via the Graph
API. Specifically, posts against [user_id]/feed where [user_id] is
different from the session user, or stream.publish calls where the
target_id user is different from the session user, will fail. If you
want to allow people to post to their friends' timelines, invoke the
feed dialog. Stories that include friends via user mentions tagging or
action tagging will show up on the friend’s timeline (assuming the
friend approves the tag). For more info, see this blog post.
If you want to allow people to post to their friends' timelines, invoke the feed dialog.

Resources