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.
Related
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
I'm trying to upload an image to facebook using the iOS SDK from Facebook.
To upload an image, I'm doing following:
-Upload image to a private server in order to get the image URL.
-Open facebook dialog with "feed" in order to upload a comment to facebook wall.
My goal is to avoid using a private server to upload the picture and get the URL, in order to upload the image to facebook directly from iPhone.
I've been googling and I found several solutions to upload images directly to facebook, but is without using the default dialog that includes the SDK.
Is any way to upload images directly from device, using the FB dialog object? Is not an option for me to make the Views to replace the dialog.
Thanks in advance.
As far this is my code to publish on facebook:
+(void)composeFacebookWithImageUrl:(NSString *)imageURL image:(UIImage *)image delegate:(id)delegate
{
Facebook *_facebook;
_facebook = [[[Facebook alloc] initWithAppId:kAppId andDelegate:delegate] autorelease];
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"Always Running",#"text",#"http://itsti.me/",#"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
#"Ragdoll", #"name",
#"The Ragdoll maker app", #"caption",
#"Share with your friends", #"description",
#"http://www.im2.es/", #"href", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Share on Facebook", #"user_message_prompt",
actionLinksStr, #"action_links",
attachmentStr, #"attachment",
#"touch",#"display",
imageURL, #"picture",
nil];
[_facebook dialog:#"feed"
andParams:params
andDelegate:delegate];
}
Thanks.
Have you looked into ShareKit? I'm using it to share images in my apps and it works great.
https://github.com/ShareKit/ShareKit
I have an app, it takes screenshot of itself and I would like to post it on user's wall along with a comment.
The problem is, I seemingly tried every option and none of it works:
[facebook dialog:#"feed" ...] doesn't work because you can supply only a URL, not a UIImage.
[facebook requestWithGraphPath ...] doesn't work because the user is not prompted for the comment.
I could first (silently) try to upload the screenshot with requestWithGraphPath and then feed its newly created URL to dialog which doesn't work because of "FBCDN image is not allowed in stream". All of this is of course using callbacks which, including login callback, makes for nice big mess.
I even tried ShareKit but forgot about it after the app strangely could/couldn't login.
Please, how can I share both an image and a comment?
If you are using facebook's latest iOS SDK, in Hackbook sample app, look for APICallsViewController.m file. There is this method that you can post using UIImage directly:
/*
* Graph API: Upload a photo. By default, when using me/photos the photo is uploaded
* to the application album which is automatically created if it does not exist.
*/
- (void) apiGraphUserPhotosPost {
NSString *sourcePath = [[NSBundle mainBundle] resourcePath];
NSString *file1 = [sourcePath stringByAppendingPathComponent:#"/MP1101frame1002.jpg"];
UIImage *img = [[[UIImage alloc]initWithContentsOfFile:file1]autorelease];
[self showActivityIndicator];
currentAPICall = kAPIGraphUserPhotosPost;
HackbookAppDelegate *delegate = (HackbookAppDelegate *) [[UIApplication sharedApplication] delegate];
// Download a sample photo
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
// UIImage *img = [[UIImage alloc] initWithData:data]; //here you can insert your UIImage
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
yourMessageHere, #"message", //whatever message goes here
img, #"picture", //img is your UIImage
nil];
[[delegate facebook] requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
If you haven't already, you may want to try the latest development branch of ShareKit at this address:
https://github.com/Sharekit/Sharekit
It has significant improvements added by the community over the canonical version.
I'm using FBConnect to post a link to a user's wall. I am using the FBDialog api instead of using graph paths:
[facebook dialog:#"feed" andParams:_params andDelegate:_delegate];
Everything posts correctly except when the wall is viewed, there is no share link, only the like and comment links. I've researched this and figured out that this appears to be unique to using FBDialog.
If the graph path method is used:
[facebook requestWithGraphPath:_path andParams:_params andHttpMethod:#"POST" andDelegate:_delegate];
the share link shows up.
To fix this, I have added a custom link using the actions parameter provided by FBDialog:
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
#"Share", #"name",
#"http:???", #"link",
nil],
nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
[params setObject:#"link" forKey:#"type"];
[params setObject:self.url forKey:#"link"];
[params setObject:self.title forKey:#"name"];
[params setObject:self.caption forKey:#"caption"];
[params setObject:actionLinksStr forKey:#"actions"];
This again, works correctly and creates a share link. The question I have is: What url do I use to share the wall post? Any ideas?
Thanks so much!
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/