post image on Facebook wall and facebook friends wall - iphone

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

Related

(Facebook SDK 4.x) Sharing a link to a friends wall

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"]);
}
}];
}

iOS: Incorrect/Repetitive Facebook Request Message

I'm using the Facebook SDK and Parse.
I am submitting additional requests for the users email, events, and their friends' events.
Although I receive this info successfully, users who are logged into iOS' facebook system get this popup when I request permissions.
Notice that they are already logged into facebook (via the settings app) and they are simply getting a message to approve the request.
As you can see, it repeats the info about basic profile and friend list (FB login gives you this by default) and doesn't even mention the email. Since I doubt Apple or FB has made this kind of mistake, I assume it has something to do with me. Here is how I request access using FB and Parse.
// The permissions requested from the user
NSArray *permissionsArray = #[ #"email, user_events, friends_events"];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
[activityIndicator stopAnimating]; // Hide loading indicator
if (!user) {
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
}
} else if (user.isNew) {
NSLog(#"User with facebook signed up and logged in!");
[self.delegate ViewWasDismissed];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
} else {
NSLog(#"User with facebook logged in!");
[self.delegate ViewWasDismissed];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
}];
again, this request WORKS. Therefore, I can't imagine what I could be doing wrong, but the message is strange. Any ideas?
EDIT: I tried deleting my account from the iOS facebook system and requesting directly through the app. This time I got this message:
Notice that here, the user is logged into facebook via the FB app and simply gets this (correct) message to accept permissions.
Is this some kindof bug with Apple's Facebook system?
This is the correct behaviour that will happened for iOS. Since iOS 6, Apple has integrated Facebook to the devices. Therefore, users can log in Facebook from Settings page. Below are the scenario that explain your confusions.
Scenario 1: Logged in to Facebook from Settings page
The app will automatically detect the Facebook account from your device if there's any, and prompt you the permissions request with UIAlertView. This only happen if you're using latest SDK and I am not so sure since which SDK that Facebook released for iOS has this.
Scenario 2: Not logged in to Facebook from Settings page (Old way)
The app will lead you to Facebook app if it's installed in your device. Else it will lead you to Safari with Facebook mobile page open and ask you for permissions that the app required.
Hope this help :)

Is it possible for user of an ios app to like a URL on facebook using the facebook-sdk?

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.

Facebook iOS SDK Logout

I'm using the official and updated Facebook iOS SDK.
We're developing an application on an iPad that is used inside a physical store using an in-house distribution profile. Where customers can login to their Facebook account on an iPad that's publicly available to improve their shopping experience.
The problem I came across is that when a user logs into their Facebook account, the next user (customer) will still be logged in with the previous users' credentials (You have already authorized xxx, Press "Okay" to continue). Ofcourse this is not okay.
Is there a way to actually logout (sign off, clear credentials, or what ever) the previous (or current) user so the next user can fill in its own username and password.
Unfortunately [[FBSession activeSession] closeAndClearTokenInformation] doesn't quite do the trick.
This is a part of the code so far:
// ....
[[FBSession activeSession] closeAndClearTokenInformation];
[FBSession.activeSession openWithCompletionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
// More code ...
}];
// ...
PS. The cookie 'workaround' doesn't work for me (obviously)
From your context, I'm assuming your device(s) does not have the Facebook app installed nor do you expect to use iOS 6 system authentication which would leave the default login behavior to use Safari. If you were to clear the Safari cookies, that should work but for a smoother experience in your scenario you should use the FBSession openWithBehavior:completionHandler: method and specify a behavior of FBSessionLoginBehaviorForcingWebview so that it uses the inline webview dialog for authentication.
See the SwitchUserSample in the Facebook iOS SDK for an example since that sample demonstrates an app that can toggle between multiple accounts.
Try with this code. I think it will help you.
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
If you are using facebook sdk 4.1.0 just call bellow method
if ([FBSDKAccessToken currentAccessToken]) {
[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];
}

Facebook Connect SSO not working on some iPhones

I have implemented FBConnect SSO in my iphone application according to this tutorial. I have tested it on two phones so far, one of which lets me use the function just fine, whereas the other phone simply opens up the Facebook app and closes it right away. I am able to establish a valid session, yet the dialog seems to just close on me on one of the ones.
What could be the problem? Any help is much appreciated.
I think that your problem is that you dont have the proper configuration, either in the client side (your app) or in the server side (the FB app configuration). Please, check both things as follows:
Client app:
Make sure that you have introduced the correct FBAppId into your Info.plist as a URL handler. Facebook will try to open the app by using this handler, and if it doesn't work, your app will not be opened.
(replace the XXXXXXXXXX with your FB appID)
Check whether your app (in the appDelegate) handles the custom URL added above:
- (BOOL)handleOpenURL:(NSURL*)url
{
NSString* scheme = [url scheme];
NSString* prefix = [NSString stringWithFormat:#"fb%#", facebookAppId];
if ([scheme hasPrefix:prefix]) {
return [fb handleOpenURL:url];
}
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [self handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [self handleOpenURL:url];
}
Server side
Check that you have correctly configured your bundleId in the FB config page. You can check this in https://developers.facebook.com/apps, selecting you app, and then in the edition panel:
If you have both things correctly configured it should work in any case (with the FBapp installed or Safari based).
I have seen this with the 3.0 SDK. The reason it occurs is because of the way facebook caches access tokens. Access tokens are cached both in your app, and in the facebook app on the device (at least conceptually).
If it's the first time you started your app on the device, facebook won't have a valid access token cached in your app. However, it may still have a valid access token in the facebook app for your app. If it finds one on the facebook side, then it doesn't have to ask the user again, so the dialog appears, then disappears, and it sends back the access token. The access token is then cached in your app.
If you restart your app (without deleting it), you won't see the login dialog at all since the access token is now cached in your app. If you delete your app on the device and login again, you'll see the same behavior, as long as facebook can find a cached token on it's side.
I have found a solution to this problem. Here is some sample code:
if (![FBSession activeSession].isOpen) {
FBSession *session = [[FBSession alloc] initWithAppID:nil permissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone urlSchemeSuffix:nil tokenCacheStrategy:nil];
[FBSession setActiveSession:session];
[session openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
// NOTE openActiveSessionWithPermissions causes the facebook app to hang with a blank dialog if my app is installed, authed, and then reinstalled. openWithBehavior
// does not. I think it has something to do with the FBSession activeSession.
// [FBSession openActiveSessionWithPermissions:self.permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
switch (status) {
case FBSessionStateOpen:
[self getFacebookUser];
break;
case FBSessionStateClosed:
[self fbSessionClosed];
break;
case FBSessionStateCreated:
[self fbSessionCreated];
break;
case FBSessionStateCreatedOpening:
[self fbSessionOpening];
break;
case FBSessionStateClosedLoginFailed:
[self fbSessionClosedLoginFailed];
break;
case FBSessionStateOpenTokenExtended:
[self fbSessionOpenTokenExtended];
break;
case FBSessionStateCreatedTokenLoaded:
[self fbSessionCreatedTokenLoaded];
break;
}
}];
}
}
openActiveSessionWithPermissions causes problems, but openWithBehavior does not. openActiveSession makes the same openWithBehavior call, but I think the timing of setting the active session is different, and hence does not work. If I set the active session before calling openWithBehavior, everything seems to work fine. As far as your app and the end user are concerned, everything is identical.
You need to insert suitable logging throughout your code, post the code, and post what logs are being made in the working and the failure cases.
To make a log (see here for more advanced techniques):
NSLog(#"My log text");
At a minimum you need to add logs in all the callbacks from the Facebook API (even the ones you aren't using), and in your handleOpenURL and openUrl methods in the application delegate.
Your logs will appear in the Console in the Xcode Organizer when you connect the device you are testing with - that should show you what is happening.
FYI, the Facebook SDK code will first attempt to use the native app if it is installed, otherwise it will launch the Safari browser to ask for authorization through the web version of Facebook.
You should double check your Facebook URL scheme configuration, as described in the answer by Angel García Olloqui.