please check my code:
Here i'm trying to upload screenshot to facebook album, but that doesnt works
CGImageRef screen = UIGetScreenImage();
self.image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.image, #"picture",
nil];
[self.facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
self.image is ok, it is used in other parts of the code and everything looks nice. if i set up self.image for ex for [uiimage imagenamed#"example.png""] everything works nice. the different is that one uiimage exists on in memory and another both in memory and device.
what can bee wrong?
thanks
solved. the problem was the wrong way of making a screenshot.
Related
I am making an app that lets users post to their Flickr photo streams. I am using ObjectiveFlickr to handle the authorization and posting process.
For posting a single picture i am using the following code:
if (isSinglePic) {
UIImage *img = self.singlePic;
NSData *JPEGData = UIImageJPEGRepresentation(img, 1.0);
self.flickrRequest.sessionInfo = __kUploadImageStep;
[self.flickrRequest uploadImageStream:[NSInputStream inputStreamWithData:JPEGData] suggestedFilename:self.descriptionTextField.text MIMEType:#"image/jpeg" arguments:[NSDictionary dictionaryWithObjectsAndKeys:#"0", #"is_public", nil]];
//[NSDictionary dictionaryWithObjectsAndKeys:photoID, #"photo_id", #"PicknPost", #"title", #"via PicknPost", #"description", nil]]
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
This works just fine. However, when i try to post multiple pics that i stored in a NSMutableArray, ObjectiveFlickr uploads only the first picture.
My code for posting multiple photos looks like this:
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:picsToPost copyItems:YES];
for (UIImage *imgToPost in array) {
NSData *JPEGData = UIImageJPEGRepresentation(imgToPost, 1.0);
self.flickrRequest.sessionInfo = __kUploadImageStep;
[self.flickrRequest uploadImageStream:[NSInputStream inputStreamWithData:JPEGData] suggestedFilename:self.descriptionTextField.text MIMEType:#"image/jpeg" arguments:[NSDictionary dictionaryWithObjectsAndKeys:#"0", #"is_public", nil]];
[UIApplication sharedApplication].idleTimerDisabled = YES;
Does anyone have an idea why the for-in statement doesn't work?
Any help would be appreciated.
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 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 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.
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 ??