Upload photo to a facebook fan page - ios

here's my code keypoints that I'm using in order to upload photo to my fan page
_permissions = [[NSArray arrayWithObjects:#"read_stream", #"offline_access", #"publish_stream", #"manage_pages", #"user_photos", #"friends_photos",nil] retain];
[_facebook requestWithGraphPath:#"/me/accounts" andDelegate:self];
I parse the page access_token from results and use it for next requests impersonating page, and I can successifuly parse out page owner info from the result, so I guess my access_token is ok
- (IBAction)getUserInfo:(id)sender {
_facebook.accessToken = self.pageAccessToken;
[_facebook requestWithGraphPath:#"me" andDelegate:self];
}
But If I try to upload photo to my page album like this:
- (IBAction)uploadPhoto:(id)sender {
NSString *path = #"http://dl.dropbox.com/u/xxxxxxx/Icon.png";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
_facebook.accessToken = self.pageAccessToken;
[_facebook requestWithMethodName:#"photos.upload"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
//or like
// [_facebook requestWithGraphPath:#"/me/photos" ...
// [_facebook requestWithGraphPath:#"/<PAGE_ID>/photos" ...
// [_facebook requestWithGraphPath:#"/<ALBUM_ID>/photos" ...
[img release];
}
I always get error:
Error Domain=facebookErrDomain Code=190 "The operation couldn’t be completed. (facebookErrDomain error 190.)" UserInfo=0x15fca0 {request_args=(
{
key = method;
value = "photos.upload";
},
{
key = sdk;
value = ios;
},
{
key = "sdk_version";
value = 2;
},
{
key = "access_token";
value = "1939755xx612731|8ceab6c65ce0194d079f41ef-1068726246|3x2697618282|xdSRakxsdjezx9N1dnr9cRe6ICk";
},
{
key = format;
value = json;
}
), error_msg=Invalid OAuth 2.0 Access Token, error_code=190}
}
(note: i've modified slightly access_token just for protection)

Hey jackiedigital, I this the "manage_pages" permission is only compatible with the Graph API.
Check out the Last permission on this page: http://developers.facebook.com/docs/authentication/permissions/

Related

Open Facebook iOS native app WITH back button to my app

I am trying to open facebook app via AppLinks url , it opens user profile/page but does not show button "back to referer app" , I am providing "referer_app_link" data ,
I have generated JSON by this reference http://applinks.org/documentation/#applinknavigationprotocol
NSDictionary *dict = #{
#"target_url" : #"fb://profile/USER_ID",
#"referer_app_link" : #{
#"target_url" : #"MY WEBSITE",
#"url" : #"CALLBACK URL",
#"app_name" : #"MY APP NAME",
#"app_store_id" : #"MY APP STORE ID"
}
};
NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
jsonString = [jsonString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *stringUrl = [NSString stringWithFormat:#"fb://applinks?al_applink_data=%#",jsonString];
NSLog(#"String url is %#",stringUrl);
NSURL *url = [NSURL URLWithString:stringUrl];
if([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
} else {
NSLog(#"Cant open %#",url);
}
any ideas ? is Facebook supposed to have "back button" at all ?
my url scheme is set up correctly ...
Update:
NSDictionary contains all valid values , I dont want to publish them at the moment , but url , name , store id ... etc all are valid
Update #2:
Since iOS 9 , this is done by iOS System automatically.
applink is not wired into the FB friend profile page if you simply use the FB Custom URL to link into FB.APP or to safari it will not go back to your app automatically.
The alternative to this is to use the FB IOS SDK and Pick and display the remote user within your app as follows: (code from HelloFacebook sample app (comes with the SDK)
- (IBAction)pickFriendsClick:(UIButton *)sender {
FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = #"Pick Friends";
[friendPickerController loadData];
// Use the modal wrapper method to display the picker.
[friendPickerController presentModallyFromViewController:self animated:YES handler:
^(FBViewController *innerSender, BOOL donePressed) {
if (!donePressed) {
return;
}
NSString *message;
if (friendPickerController.selection.count == 0) {
message = #"<No Friends Selected>";
} else {
NSMutableString *text = [[NSMutableString alloc] init];
// we pick up the users from the selection, and create a string that we use to update the text view
// at the bottom of the display; note that self.selection is a property inherited from our base class
for (id<FBGraphUser> user in friendPickerController.selection) {
if ([text length]) {
[text appendString:#", "];
}
[text appendString:user.name];
}
message = text;
}
[[[UIAlertView alloc] initWithTitle:#"You Picked:"
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
}];
}
Note - the sample currently just picked the name property from the FBGraphUser Class instance ....
user will have other properties birthday, sex etc, just lookup header file within the SDK or look up FB documentation.

control is not returned from web view shouldstartload delegate method

In my application i am using Uiwebview for displaying vimeo authorization page, after the user has authorized it, i have to parse the url for OAtoken and dismiss it, for that i am using should startLoad delegate method, but after the process is over and when i am returning NO, the control is not transferred back...
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSURL *url = [request mainDocumentURL];
NSString *str1 = [url absoluteString];
NSString *str = #"https://vimeo.com/oauth/confirmed";
//[webView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_cork.png"]]];
if([str isEqualToString:str1])
{
//removing the webview after the user approves.
//[webView removeFromSuperview];
return YES;
}
//parsing the redirected url to get the oauth_verifier.
URLParser *parser = [[URLParser alloc] initWithURLString:str1];
Oauth_verifier = [parser valueForVariable:#"oauth_verifier"];
//getting the final access token by giving the oauth verifier.
NSURL *url_access = [[NSURL alloc] initWithString:#"https://vimeo.com/oauth/access_token"];
OAMutableURLRequest *reques_access = [[OAMutableURLRequest alloc]initWithURL:url_access consumer:consumer token:acessToken realm:nil signatureProvider:nil];
OARequestParameter *p2 = [[OARequestParameter alloc] initWithName:#"oauth_verifier" value:Oauth_verifier];
NSArray *params2 = [NSArray arrayWithObject:p2];
[reques_access setParameters:params2];
[reques_access setHTTPMethod:#"GET"];
OADataFetcher *fetcher_access = [[OADataFetcher alloc]init];
[fetcher_access fetchDataWithRequest:reques_access delegate:self didFinishSelector:#selector(acessTokenTicket:didFinishWithData:) didFailSelector:#selector(acessTokenTicket:didFailWithError:)];
//if the access token is successfully generated then the control transferrd to acessTokenTicket did finish with data
// Return YES if you want to load the page, and NO if you don't.
NSLog(#"at return yes");
if (i==1) {
NSLog(#"returning no");
[webView removeFromSuperview];
return NO;
}
return YES;
}
i am sure that it is going to return no because the statement "returning no" is printed, but the control is not returned,i have given the statement
NSLog(#"returned from web view delegate");
in the main function to know whether the control is returned it is not returned and also the operations below are not performed.

Facebook SDK loads default image and not image from my profile, why?

I've got these facebook permissions set in my app:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"user_games_activity",
#"friends_games_activity",
#"publish_actions",
#"user_photos",
nil];
[[myDelegate facebook] authorize:permissions];
I'm making a request like so :
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"name,picture",#"fields",nil];
[[delegate facebook] requestWithGraphPath:#"me" andParams:params andDelegate:self];
And handling the response like :
else if([request.url rangeOfString:#"me"].location != NSNotFound)
{
NSString *username = [result objectForKey:#"name"];
NSLog(#"We think the username is %#", username);
helloGreeting.text = [NSString stringWithFormat:#"Hello %#", username];
NSString *pictureUrl = [result objectForKey:#"picture"];
NSLog(#"Now loading image [%#]", pictureUrl);
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:pictureUrl]];
profilePhoto.image = [UIImage imageWithData:data];
}
The log output I get is :
2012-06-26 15:10:49.002 FacebookIntegrator[10549:f803] We think the username is James Elsey
2012-06-26 15:10:49.003 FacebookIntegrator[10549:f803] Now loading image [http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yo/r/UlIqmHJn-SK.gif]
Question : Why does it obtain a default generic facebook icon rather than my own profile picture? Using the same access tokens on the Graph Explorer I can get to my profile picture image URL
The documentation for user_photos states :
Provides access to the photos the user has uploaded, and photos the
user has been tagged in
User profile picture do not require user_photos permissions. Picture is likely coming from facebook cache, you should use following url for picture.
http://graph.facebook.com/<facebook id>/picture

Add Image to Facebook Wall

I am trying to implement a previous answer. Here is the code recommended:
-(void) postImageToFB:(UIImage *) image
{
NSData* imageData = UIImageJPEGRepresentation(image, 90);
Facebook* fb = [(uploadPicAppDelegate *)[[UIApplication sharedApplication] delegate] facebook ];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[fb accessToken],#"access_token",
#"message text", #"message",
imageData, #"source",
nil];
[fb requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
But I am getting a error not found on the term: uploadPicAppDelegate
I can't find this in the Facebook sdk or a search of the web (other than additional similar code). Is this a custom created data type --or -- am I missing a file that needs to be imported?
Thanks.
In your params dictionary the value for #"source" should be a link for the picture and not a NSData object.

I've problem with Facebook SDK for iOS

NSLog(#"%#",selectedImage);
if (self.selectedImage != nil) {
UIImage *img = self.selectedImage;
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
#"iOS Apps with FBConnect",#"caption",
nil];
[facebook requestWithGraphPath:#"me/photos/Wall"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
[img release];
}
I've this code.,
I use Facebook graph API for post photo to my wall.
but Photo has been upload to other album
Can I select album to upload photo ??
or
I'd like my photo upload into "Wall Photos" album ??

Resources