I'm currently updating from Facebook SDK 3.x to 4.x on iOS and Android and can't seem to figure out how to share a link to a friends wall. Previously I used FBWebDialogs that accepted a "to" field in the parameters, but now using the FBSDKShareLinkContent and FBSDKShareDialog there doesn't seem to be any option like this.
I couldn't find any explicit mentioning of fully dropping support for this in 4.x, so would anyone know if this is still possible in some way? Preferably with a dialog and not behind the scenes.
Thanks.
This piece of code should do the trick..
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[[[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/feed"
parameters: #{ #"message" : #"your messag / link"}
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"Post id:%#", result[#"id"]);
}
}];
}
Related
I followed the set up for my own application. https://developers.facebook.com/docs/ios/getting-started/
I then used the overview example, found here: https://developers.facebook.com/docs/ios/share-dialog/
NSURL* url = [NSURL URLWithString:#"https://developers.facebook.com/"];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
The share dialog appears, like in the example. I press post and it successfully returns to the app. All looks like its working right? But when I return to the facebook wall and my profile there is no status update. The logs are not displayed so something is going wrong.
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
Any ideas? Facebook redirect you to stackoverflow to get help because they have facebook developers registered.
First, the final part on the first link, about the .plist, is really important. It has to be with the correct info from your app, in order to the share feature to work. Re-check that if you can.
Anyway, the NSLog not printing anything on the console is strange, have you tried searching(command + f) for the message output on the console? Did you try debugging your app and putting breaking points on the 'if' condition to see the state of the error instance?
I don't know if you didn't put it here, or forgot to do it on code, but are you logging the user and checking if the facebook user session is valid? That has to be checked in order for the share to work.
PS: If you are using your facebook App on sandbox mode, any share you do, will only appear on the timeline of the users that are allowed to use the fbApp.
I am creating an iOS app where I want to allow the user to like a specific URL. I've tried to use the following code (as mentioned on the Facebook developers page) to like a specific url:
**- (IBAction)likeClicked:(UIButton *)sender {
SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
[FBSession setActiveSession:appDelegate.session];
if (appDelegate.session.isOpen)
{
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"object"] = #"http://samples.ogp.me/226075010839791";
[FBRequestConnection startForPostWithGraphPath:#"me/og.likes"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"Error %#",error.localizedDescription);
NSLog(#"result %#",result);
// handle the result
}];
}
}**
But the above code only allows me to like the URL if I am authorized as an admin of that app on the facebook developer page.
If I am not an admin to the app with that specific app id , I get an error description as following:
Error The operation couldn’t be completed. (com.facebook.sdk error` 5.)
There are different solutions given on Stack Overflow for this but none of them seem to be working for me. I've checked for permissions and I have added the "publish_actions" permission to permissions list.
Is there another reason why i might be getting this error?
Is there another workaround using which i can like a specific URL on facebook?
There would be couple of places to check
- Is your Facebook app under "sandbox mode", if it is you will have to turn it off once you are sure with your development.
If you have just created a FB graph action:
You are required to submit the action through the FB developer console and it usually takes couple days for them to approve, and once approved other users can start using the "like" action.
Until you get the action approved, only the App developers, testers and admins (on the FB developer site) for this particular app would be able to complete the action and see the results on their FB timeline.
I'm using the following code to post to the user's wall. It works fine, but I noticed that it also created a photo album named after my app, and added the image to that album. Is this the expected behavior for an iOS app? Is there any way to just post to the wall without saving the image in the user's account?
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error)
{
// output the results of the request
NSLog(#"Error - %#", error);
NSLog(#"Result - %#", result);
};
UIImage *img = [logo getImage];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Test Message",#"message",img,#"picture",nil];
[FBRequestConnection startWithGraphPath:#"me/Photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:handler];
#GoldenJoe , You are using a custom application to POST an image on facebook. This way when ever you register an application you are provided with an App ID/API Key) . While POSTing an image from your iPhone application , facebook creates a separate album with the name you used to register the above mentioned application on Facebook.
This is all normal that a separate album is being create by Facebook on its own and all image that you post using that application credential (APP ID) are clubbed under the same album. You might like to give a look to the Album and Photo to better understand the concept.
Hope it helps!!
I have followed all the directions from the Facebook Developer website about integrating Facebook SDK 3.1 into iOS 6. My code runs perfectly on the iPhone 6.0 Simulator (user can log into Facebook), but when I run the app on my iPhone, the function [FBRequest requestForMe] startWithCompletionHandler] doesn't generate a response. According to the Facebook Developer website, it should either be successful or return an error, but it does neither. The app just sits there waiting for a response that never comes. My code is below:
- (void)populateUserDetails {
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
NSLog(#"logged in");
} else {
NSLog(#"error: %#", error);
}
}];
} else {
NSLog(#"no active session");
}
}
Using breakpoints, I determined that the activeSession is always open, so the startWithCompletionHandler: method is actually called. Maybe it's a build problem since it runs fine on the Simulator? Any ideas?
make sure that a "0" value hasn't been inserted automatically for your App Store
ID
App Store ID is different than Bundle ID. Like it says on Facebook: "For security reasons, we check the bundle ID before authorizing your app". So you should set that exactly as the same as it is in Xcode which you did.
But App Store ID ("iPhone App Store ID that we can link to on Facebook") you set them when you already submitted you app and it's accepted. Therefore, for developing purpose you should set iPhone and iPad(if any) to 0 which I did and it's working fine on both Simulator and iPhone iOS 6.0.
It wasn't because of that 0, maybe you fixed something else?
Answered my own question: go to your Facebook app page and make sure that a "0" value hasn't been inserted automatically for your App Store ID. I had already set my bundle ID to the correct value (which you also have to do), but overnight, Facebook automatically set the App Store ID value to 0. Everything worked as soon as I removed that value.
I am very tired with the problems of API, like Facebook Graph API, weather API etc.
I've used both API in my project. Graph API for Facebook and Google weather API for weather, but now on time of project completion, both API are not working. Google weather API depreciated in November,
And the Facebook features I've been using (post image on wall and post image on friend wall) were working last day, but now they don't.
The problem is that when I log in, I get the message The page you requested is not Found and below a link to go back to the previous page.
And when i click the link "back to previous page" it shows message:
An error has occurred with AppName, please try again
API error code : 100
API error Description : Invalid Parameter
Error_message : cancel_URL URL is not properly formatted
I wants to know solution of Facebook API. Is this problem is with every developer? if API modified or changed what we can do regarding?
How long ago did you update your facebook API? About two weeks ago I had to remove my entire API, redownload, and change all the posting code my app was using. It stopped working entirely and had no idea until app users complained. Some necessary changes for the new facebook API:
Facebook recommends putting these in your appDelegate if you look at the newest sample apps.
#import <FacebookSDK/FacebookSDK.h>
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [NSArray arrayWithObjects:#"publish_actions", nil];
return [FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if(state==513){
//facebook usage has been approved
}
}];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// We need to handle URLs by passing them to FBSession in order for SSO authentication
// to work.
return [FBSession.activeSession handleOpenURL:url];
}
And whereever you want to make your post put something like this:
if(facebookEnabled==YES)
{
NSString *fbText=[NSString stringWithFormat:#"whatever text you want to post";
[FBRequestConnection startForPostStatusUpdate:fbText
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
}];
}
Let me know if you have questions. Hope it helps!
Well I'm not sure it's your code's fault but Facebook is having issues right now.
My FB app in iOS doesn't work anymore. You can try again by enabling sandbox mode (in FB app settings) with a developer account. It works for me.
http://developers.facebook.com/bugs/463219573709230?browse=search_504fc79a6ea272d92740759
look on my solution, but it's only for posting on user wall
http://www.developers-life.com/facebook-compose-view.html