iPhone Facebook image upload not working, tried everything - iphone

I'm losing my mind over trying to get Facebook SDK for iPhone to upload UIImage.
Here's what I'm doing:
1) Creating facebook property:
facebook = [[Facebook alloc] initWithAppId:#"111111111"];
2) Calling authorize:
[facebook authorize:[NSArray arrayWithObjects:#"publish_stream", nil] delegate:self];
3) Setting params:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image, #"picture", nil];
4) Calling post:
[facebook requestWithMethodName:#"photos.upload" andParams:params andHttpMethod:#"POST" andDelegate:self];
When loging in I get the authorize dialog. When trying to upload I receive error 101, Invalid API Key. I've copied the key from FB, I've included it as shown above and I've also included it in .plist (fbAPI_KEY). What the hell am I still missing here? When asked to authorize it did show the name of the app just fine so the key must be correct. I can also post feeds and they appear on users wall, but images just won't upload.

That's a bit weird, I've got the exact same four lines of code which work fine for me. (Although, your app id is a bit shorter than it should be, mine is roughly twice that size).
One thing you may be forgetting about: when are you using each line? You should wait till each of the previous tasks is completed by using the facebook delegates, eg:
- (void)fbDidLogin; //part of the <FBSessionDelegate> protocol
Use these methods to control when the next part of the uploading process should occur, and check for errors along the way. You may be trying to send the photo before the login process has actually finished - use the delegate methods to prevent this.

I think you have to use graph API for uploading images
Check Out:
Ref URL: http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-photos-and-add-a-like-button-from-your-iphone-app
Hope this helps....

Related

iOS facebook sdk how to download album, profile photos data

I would like to allow my iPhone App users to view and select from their facebook profile photos, download the photo to use as a profile pic. I am currently using the Facebook SSO SDK and successfully logging in and accessing Graph information. Have tried to access photo information (after successful SSO login) using
[facebook requestWithGraphPath:#"me/albums"];
but I just get an empty data object in return. I've tried using the Facebook API explorer, which is very helpful, and it does give me data for /picture and /photos and /albums. For some reason I don't get the same data using requestWithGraphPath with me/albums, me/picture or me/photos. Just plain "me" works fine but doesn't give me any picture info. Can anybody tell me what I'm doing wrong?
Note: this is the API reference: Facebook Graph API
I did get picture profile to work like this:
[facebook requestWithGraphPath:#"me?fields=picture"];
Update: really I want all of the Profile Photos which is a photo album so I need to know how to access albums through iOS. The profile picture I have successfully obtained now.
I have added permissions "user_photos" and "friends_photos" for photo albums according to API:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"user_likes",
#"user_birthday",
#"email",
#"publish_stream",
#"publish_actions",
#"user_photos",
#"friends_photos",
nil];
[facebook authorize:permissions];
When I say I'm getting empty data, this is the JSON result (in request:didLoad:) that gets returned:
{
data = (
);
}
From my log file output:
- (void) request:(FBRequest *)request didLoad:(id)result{
NSLog(#"%#",result);
}
Final Note: What finally worked was to use another device, which updated my permissions and then everything started working! My best guess is that the emulator and my iPhone were not updating my facebook permissions so I was being denied access to photos and getting an empty data array.
This SO question was a big help also: How to get photos of a facebook album in iPhone SDK?
For the sake of future viewers, I'm putting the answer to my own question since I haven't received a complete answer from anyone else.
First, you must have the right permissions, either "user_photos" or "friends_photos". Then you have to make sure that your test device updates your permissions -- I think restarting the device is what ultimately did it for me.
Once you've done that, you can get the JSON list of albums, after logging in via SSO, using this call:
[facebook requestWithGraphPath:#"me/albums" andDelegate:self];
This will give JSON array (under key data) with all kinds of information about each album, including the ID. To get a list of photos for a particular album ID (say its '123456789') do the following:
NSString * albumId = #"123456789";
NSString * path = [NSString stringWithFormat:#"%#/photos", albumId];
[facebook requestWithGraphPath:path andDelegate:self];
Your response will of course come via the FBRequestDelegate method request:didLoad where you can process the JSON data.
Download the FBGraph Api documents folder then add it to in your folder. and read the instruction on facebook developer site http://developers.facebook.com/docs/reference/api/.
This is the sample code - sample code
In this you will get a user profile pic in UIAlertView. You can show it where you want.

Post to facebook and unlock levels

I'm programming my own iPhone game and since I don't want the users to pay for my levels, I'd like to allow them to post something on their FB or twitter timeline. Once it's done, I'd like to unlock the level for free, and do that for each levels pack.
Anyone has an idea on how to do this ? I know I can use Facebook API for iOS to post a status, but how can I ensure the action has been done ?
Each post or tweet has a confirmation delegate method. Add an NSNotification to unlock your level on confirmation completion.
You can do this, it's easy using graph api for FB.
You can say user to post message hardcoded in you code and you receive response from api that message is posted on his wall then you can unlock the level.
Also if you want that user can't edit message then you need to post message in background and it easy like below code.
NSMutableDictionary *dictPara = [[NSMutableDictionary alloc] init];
[dictPara setObject:objSelGameStep.smsg forKey:#"message"];
[dictPara setObject:#"status" forKey:#"type"];
[facebook requestWithGraphPath:#"me/feed" andParams:dictPara andHttpMethod:#"POST" andDelegate:self];
i hope this may help you.

Facebook Feed Dialog keeps asking for permission

I've been trying to post a link on user's wall, by using Facebook SDK for the iOS.
I'm trying the code below and it works perfectly when I don't have the Facebook App installed. But when I have it, it just ask me to authenticate and send me back to the App. It happens even just to say that I've already gave the necessary permission, but never shows the dialog to do the share.
The code is:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:#"%# %.0f%% OFF", self.offer.description,
[self.offer.price.discountPercent doubleValue] * 100], #"name",
self.offer.store, #"caption",
self.offer.imageKey, #"picture",
#"Test", #"description",
[NSString stringWithFormat:#"http://my_url.com/id%#", self.offer.offerId], #"link",
nil];
[facebook dialog:#"feed" andParams:params andDelegate:self];
Any idea? Thank you in advance ;)
I think this is becouse of you login/logout code. when you making an autorization request to FB, one of params you sending is how long access token must "live". Make shure it lives long anoth. Or, somewhere in the code you invalidating it. May be even losting pointer to access token or something. Make sure, that acces token you use to post is validate at the moment you posting. I suggest you to use official SDK for FB: it's really simple and without any problems. There is great tutorial how to use it: http://developers.facebook.com/docs/mobile/ios/build/

Objective-C/iPhone - oAuthException when using "me/checkins" as part of the Facebook Graph API

I am receiving the following graph response when checking users into Facebook using the Facebook Graph API. I am using the facebook-ios-sdk within my iPhone application to do this.
{"error":{"type":"OAuthException","message":"An unexpected error has occurred. Please retry your request later."}}
I have not made any changes to my code today and I know for a fact (database logs, etc) that their have been successful checkins yesterday.
I'm asking the SO community whether or not they have received similar errors and how they attempted to resolve them?
I have already tried the following:
Revoked access to my application via Facebook.
Reset my offline_access token by forcing Facebook to generate a new one.
Keep in mind my application successfully shares via peoples Facebook walls as well and this is working as expected without any problems.
I request the following permissions from my users:
#"offline_access", #"publish_stream", #"publish_checkins", #"email"
EDIT:
Okay, so this is quite strange and I'm thinking that it's an error on Facebook's end.
I use the following code to tag friends in the checkin:
if ([self.selectedFriends count] > 0) {
[variables setObject:[self.selectedFriends componentsJoinedByString:#","] forKey:#"tags"];
}
fb_graph_response = [fbGraph doGraphPost:#"me/checkins" withPostVars:variables clientId:accessToken];
self.selectedFriends is simply an NSMutableArray of Facebook profile ID's separated by commas, which is what the graph API says to use and remember this has been working fine for months.
http://developers.facebook.com/docs/reference/api/checkin/
If I remove the [variables setObject:[self.selectedFriends componentsJoinedByString:#","] forKey:#"tags"]; then the checkin works just fine for me.
It fails every time I tag one or more friends. Is anyone else receiving the same error when tagging friends in a checkin?
UPDATE 1:
Looks like other people are receiving the same problem relating to Groups:
http://forum.developers.facebook.net/viewtopic.php?pid=349396
I wonder if there's a bug at the moment relating to Checkins.
I've posted a bug:
http://bugs.developers.facebook.net/show_bug.cgi?id=18134
UPDATE 2:
Facebook were able to reproduce the bug and they're now looking into it.
i m using checkins in one of my applications , Regarding your issue ,
Yes , you are right , i had this OAUTH Exception only when sometimes you made checkins continuously with tagging friends,
Also allow permissions like #"user_checkins", #"friends_checkins", in your application
please check this link :
http://tylerwhitedesign.com/how-to-check-in-using-the-facebook-ios-sdk-and-graph-api
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[dictionary objectForKey:#"place"], #"place", //The PlaceID
coordinates, #"coordinates", // The latitude and longitude in string format (JSON)
message, #"message", // The status message
tags, #"tags", // The user's friends who are being checked in
nil];
[_facebook requestWithGraphPath:#"me/checkins" andParams:params andHttpMethod:#"POST" andDelegate: postCheckinRequestResult];
Hope this helps!

How do I like a Facebook AppID through IPhone Application?

I am developing a iPhone application in which I want to simply 'Like' my own Facebook AppID.
For Facebook integration I am using FBConnect and Graph API (https://github.com/facebook/facebook-ios-sdk/blob/master/README.mdown).
After researching, I found that I was supposed to use the following method, which I attempted to implement in the "DemoAppViewController.m" of the sample code when the 'publishStream' button was selected:
NSMutableDictionary *params = [NSMutableDictionary dictionary]; //Use an empty dictionary
[_facebook requestWithGraphPath:#"https://graph.facebook.com/163221793740496/likes"
andParams:(NSMutableDictionary *)params
andHttpMethod:#"POST"
andDelegate:(id <FBRequestDelegate>)self];
However, my FBRequest.m 'responseString' indicates: {"error":{"type":"GraphMethodException","message":"Unsupported post request."}}
What am I doing wrong and how can I make this work?
From what I understand, all I need to do is attach my accessToken to https://graph.facebook.com/163221793740496/likes. What exactly does that mean, and how is it accomplished?
Thanks in advance!
P.S. - In case there was any confusion, my post was in reference to having a user sign into Facebook with their account login via a fb like button in the application. After the user allowed the appropriate permissions, my app would 'like' the AppID with the user's account.
You can't programmatically like a page on Facebook. It would be enthusiastically abused.