posting status on facebook from ios app using facebook 3.1 SDK - ios

I am working for an iOS app and I want to integrate Facebook sdk 3.1 for posting status on facebook but I really dont have any idea how to do it. Can anybody please provide me link to easy tutorials or step by step approach for how to do it.

To set up your Xcode project, read the instructions on the Facebook developer site.
You can create / open a session using [FBSession openActiveSessionWithAllowLoginUI:YES];
To publish to your timeline, you'll need to authorise with write permissions:
[[FBSession activeSession] reauthorizeWithPublishPermissions:#[ #"publish_stream" ] defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *authSession, NSError *authError) {
// If auth was successful, create a status update FBRequest
if (!authError) {
FBRequest *postRequest = [FBRequest requestForPostStatusUpdate:#"Hello, world!"];
[postRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// TODO: Check for success / failure here
}];
}
}];

Try this:
[FBRequestConnection startForPostStatusUpdate:#"I've been through the storm, future, present and past.. Light as a feather, swift as a cat.. Clickety clack, clickety clack!!" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"posted");
}];
Hope this helps.

Related

iOS: Set profile picture to facebook

I am working on one app in that i want to set profile picture of Facebook.
I am not getting any solution to set picture using sdk so it will be fine to have solution using graph API.
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc]initWithGraphPath:#"me" parameters:#{#"fields":#"picture"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"%#",result);
}];
}
After getting result, use the nsurlsession and get data, pass into the imageview[use main thread when using uielement].

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

Facebook Like Button - canĀ“t build archive with the new feature FBLikeControl

I want to integrate Facebook like Button with the new feature FBLikeControl. On the facebook page they have written it is only for developement and not for publication on the AppStore.
Here is the Tutorial from facebook https://developers.facebook.com/docs/ios/like-button/
When I want to build an archive with my code I get the error message "Use of undeclared identifier FBBetaFeaturesLikeButton".
Is there a way to solve this problem or if there's any other alternative solution, I would appreciate that.
Here is my code:
[FBSettings enableBetaFeature:FBBetaFeaturesLikeButton];
[FBSettings enablePlatformCompatibility:NO];
FBLikeControl *like = [[FBLikeControl alloc] init];
like.frame = CGRectMake((self.frame.size.width-like.frame.size.width)/2, facebookY, 60, 20);
like.objectID = #"https://www.facebook.com/pages/abcdefgh/123456789?ref=tn_tnmn";
[self addSubview: like];
This link says:
FBLikeControl is a preview feature and may not be deployed to the App
Store. Only developers and testers of your Facebook app will be able
to use the Like Button.
is the reason you are unable to built the archive.
There are several ways to implement like, the one which worked for me is as follows:
[FBRequestConnection startWithGraphPath:#"/object-id_to_like/likes"
parameters:nil
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// Handle error here
}];
Here is the Link
EDIT: It is pretty simple, you just have to replace FBLikeControl code in your project with the above method call replacing object-id_to_like to the actual post-id/ object-id. What the method does is it POSTS a like on corresponding object/post.
In case you have problem to fetch the object id of the object/post you can fetch it using same method with the HTTPMethod parameter set to #"GET". Following code will return posts from your timeline:
[FBRequestConnection startWithGraphPath:#"/me/home"// you can change this to #"/me/feed" if required
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error ) {
if (!error){
// Fetch Post-id/Object-id here
}else{
// handle error here
}
}];

Error code 5 when publishing Facebook Open-Graph story through iOS?

I have been trying to publish a FB Opengraph story through xcode and havent been able to do so yet.
The url is a static url, with all the meta tags set in the html file itself.
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"testaction"] = #"http://myfbapp.com/fbobject.html";
[FBRequestConnection startForPostWithGraphPath:#"me/myfbapp:publish"
graphObject:action
completionHandler:
^(FBRequestConnection *connection, id result, NSError *error) {
}];
The code has been taken straight from the facebook app itself.
Thanks for any help!
Before calling startForPostWithGraphPath,
make sure the session is open:
NSLog(#"activeSession isOpen: %d", [[FBSession activeSession] isOpen]);
make sure the session has 'publish_actions' permissions:
NSLog(#"session perms: %#", [[FBSession activeSession] permissions]);
if not,
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
then ask for permission:
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
The problem was that the action had not been reviewed by FB and was in test mode. The account I was trying to post with was not the developer account linked with the FB App and therefore I was unable to post the action.
Once I logged in with my dev account, it was working fine.

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

Resources