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
}
}];
Related
I'm trying to do something that seems to be an order of magnitude more difficult than necessary.
I've got an iOS app that is written against a Parse backend. Our app's users can create items to store and they can sometimes generate alerts for these items.
I want to post a simple alert for a user to Facebook.
I've read quite a bit on the Facebook website about integrating Facebook into iOS, but their documentation is confusing and I've seen more than one person on StackOverflow mention that their iOS code is at least sometimes flawed.
Basically, the custom story will include the following items:
Story Title
Story Description (usually not very much text in here)
One or more pictures (I'd settle for 1, but I'd love to be able to post multiples)
If possible, a user-supplied GPS location.
I will admit up front that I'm a developer who is learning Facebook for work purposes, and I am far from being an expert on Facebook.
When I play around in the Facebook app, I can add a status update that can include:
Text
Picture(s)
Friends
What I'm doing
Where I am (or some location)
However, in the Facebook SDK, there appears to be only the following 2 options for posting a status update:
startForPostStatusUpdate:completionHandler:
startForPostStatusUpdate:place:tags:completionHandler:
If I'm missing something there, please let me know.
Secondly, I'm trying to follow Facebook's documentation and sample code to do the following sequence of events:
Upload and stage an image resource
Create an object (in my app, I've registered an "alert" object)
Create an action (in my app, I've registered a "post" action)
Here's the code that I've pieced together from Facebook's website (comments are mostly from other people's code, not my own):
- (void)postToFacebookWithAlert:(PFObject *)alert image:(UIImage *)image {
// Stage the image
[FBRequestConnection startForUploadStagingResourceWithImage:image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error != nil) {
// See: https://developers.facebook.com/docs/ios/errors
} else {
// Package image inside a dictionary, inside an array like we'll need it for the object
NSArray *image = #[#{#"url": [result objectForKey:#"uri"], #"user_generated" : #"true" }];
// Create an object
NSString *caption = // user-generate content
NSMutableDictionary<FBOpenGraphObject> *alert;
alert = [FBGraphObject openGraphObjectForPostWithType:#"<myapp>:alert"
title:caption
image:image
url:nil
description:alert[#"subtitle"]];
alert.provisionedForPost = YES;
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:alert completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error != nil) {
// An error occurred
} else {
NSMutableDictionary<FBGraphObject> *post = [FBGraphObject graphObject];
post[#"alert"] = result[#"id"];
[FBRequestConnection startForPostWithGraphPath:#"me/<myapp>:post" graphObject:post completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"startForPostWithGraphPath:graphObject:completionHandler:");
if (error != nil) {
// An error occurred
NSLog(#"Encountered an error posting to Open Graph: %#", error);
} else {
NSLog(#"OG story posted, story id: %#", result[#"id"]);
}
}];
}
}];
}
}];
}
I've actually gotten this code to work one time. I'm logged in as my own personal Facebook account. If I go to my activity log, I can see the items that I'm trying to post. If I go to my photos, I can see the photos that I'm trying to upload. If I view my profile from my wife's app/account, it doesn't show up.
Does anyone have working code that does what I want?
Maybe you need to set "fb:explicitly_shared" to "true" and it should be reviewed by Facebook.
After your review pass, you can add the option like below.
[post setObject:#"true" forKey:#"fb:explicitly_shared"];
I am making an iOS application where I want to get the list of all the pages that has been liked by the Facebook user. I have already used the permission 'user_likes' using Facebook Graph API. Now I want to display it.
Refer this: https://developers.facebook.com/docs/graph-api/reference/v2.2/object/likes
Kindly help.
I got my answer and this is how I made it happen:
//Page likes
/* make the API call */
[FBRequestConnection startWithGraphPath:#"me/likes?limit=10" parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
NSLog(#"Likes are:\n\n%#",result);
}];
NSString *fbCountry=[
I have used FacebookSDK.framework for Facebook integration in my application. I have to like one facebook page from application. I have used following code for liking page.
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:#"https://www.facebook.com/demoappname"
, #"object",
nil
];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"me/og.likes"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
)
{
NSDictionary *currentResult= [(NSArray *)[result data] objectAtIndex:0];
if(!error)
{
NSLog(#"there is no error");
}
else
{
NSLog(#"There is something wrong at here.");
}
}];
But I am not clear what I have to pass in "object" parameter. Can anybody help to what I am doing wrong at here.
Thanks,
If you read this documentation, it says-
The og.likes action can refer to any open graph object or URL, except for Facebook Pages or Photos.
So, liking a page with Graph API isn't possible.
The only thing you can do- add a Like Button to the page in your app.
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.
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.