Here Iam having a problem.Actually I implemented the facebook integration in my application and I need to post the images with text but I dont have any idea how to work on this.can anyone suggest this with a sample code so that it is very helpful for me.
Anyone's help will be much appreciated.
I assume that you want to draw some text in an image, and then upload the image to Facebook.
At first, we need to draw the original image and the desired text into a new image.
UIGraphicsBeginImageContext(CGSizeMake(320.0, 320.0));
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw the original image
[image drawInRect:CGRectMake(0, 0, 320.0, 320.0)];
// Draw the text
[#"text" drawInRect:CGRectMake(...) withFont:[UIFont systemFontOfSize:20.0];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
And then, convert the image into NSData and call Facebook's "photos.upload" API to upload it.
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:#"caption" forKey:#"caption"];
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
NSData *data = UIImagePNGRepresentation(newImage);
[uploadPhotoRequest call:#"photos.upload" params:args dataParam:data];
If you want to upload the images to your server, and post a small story to Facebook's wall. Use the stream API.
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = #"Prompt";
NSString *name = #"Your caption";
NSString *src = #"http://example.com/path/of/your/image";
NSString *href = #"http://what/happens/if/the/user/click/on/the/image";
NSString *attachment = [NSString stringWithFormat:#"{\"name\":\"%#\",\"media\":[{\"type\":\"image\", \"src\":\"%#\", \"href\":\"%#\"}]}", name, src, href];
dialog.attachment = attachment;
[dialog show];
Maybe you would be happy using BMSocialShare. It's a simple lib I wrote.
BMFacebookPost *post = [[BMFacebookPost alloc]
initWithTitle:#"Simple sharing via Facebook, Email and Twitter for iOS!"
descriptionText:#"Posting to Facebook, Twitter and Email made dead simple on iOS. Simply include BMSocialShare as a framework and you are ready to go."
andHref:#"https://github.com/blockhaus/BMSocialShare"];
[post setImageUrl:#"http://www.blockhausmedien.at/images/logo-new.gif"
withHref:#"http://www.blockhaus-media.com"];
[[BMSocialShare sharedInstance] facebookPublish:post];
Related
Im using UIActivityViewController for share image to social network. I need to post my image to friend's wall. Is it possible to post image to friend's wall using UIActivityViewController.
With NSData, you can add image to UIActivityViewController. Try below one.
NSString *text = #"your text goes here";
NSData *Da = UIImageJPEGRepresentation([UIImage imageNamed:#"Icon.png"], 1.0);
NSArray * activityItems = #[text,Da];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:[NSArray arrayWithObjects:nil]];
activityVC.excludedActivityTypes = #[UIActivityTypePostToWeibo]; //or whichever you don't need
[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
}];
[self presentViewController:activityVC animated:YES completion:nil];
In my App I sharing an image on Instagram. It is working well in my app.
I am using the following code.
#property (nonatomic, retain) UIDocumentInteractionController *dic;
CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/test.igo"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#", jpgPath]];
// NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#", screenshot]];
self.dic.UTI = #"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
Now I also want to share some text with the image.
As shown in the Image below. In " Write a Caption", I want some default custom text for eg. "Share this photo".
How can I do this?
Thanks in advance...
Edited
I am opening Instagram from my app for sharing images and it works fine.
But Is it possible that Can I check Whether the user has shared it successfully or not?
Means I want to perform some action in my DB when user successfully shares an image.
How can i do this?
I got my answer. Just added a line and it worked for me.
self.dic.annotation = [NSDictionary dictionaryWithObject:#"Here Give what you want to share" forKey:#"InstagramCaption"];
Thanks...
It is also documented in the official documentation at http://instagram.com/developer/iphone-hooks/
To include a pre-filled caption with your photo, you can set the annotation property on the document interaction request to an NSDictionary containing an NSString under the key "InstagramCaption". Note: this feature will be available on Instagram 2.1 and later.
You are no more allowed to share Pre-Filled Text with Instagram or Facebook.
Only Images/Screenshots can be shared via UIDocumentInteractionController.
I want get image from public perfil of Facebook and show it in my iPhone. I'm using the Facebook Developer method "getPhoto" but I canĀ“t show any image?
Can someone help me?
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
As told Previously your problem to retrieve the object id. Here is the solution:-
To retrieve the images of your friend. Create the connection with the url
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/me/friends?access_token=%#",accessTokenValue];
above url when hit returns an array of dictionary in which name of your friend and his id is written. Just Json parse that you will get the id of the person.
you need to use graph api for this purpose
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
I'm developing an iphone app with XMPP.
I'm trying to print the images of the logged in users in the chat room. This is the code I have.
XMPPvCardAvatarModule *avatar = [[XMPPvCardAvatarModule alloc]initWithvCardTempModule:[[self appDelegate]xmppvCardTempModule]];
XMPPJID *jidUser = [XMPPJID jidWithString:key];
NSData *foto = [[NSData alloc]initWithData:[avatar photoDataForJID:jidUser]];UIImage *pic = [UIImage imageWithData:fotoData];
UIImageView *picVista = [[UIImageView alloc] initWithImage:pic];
[self.commentsGente addSubview:picVista];
But that NSData is always 0KB, so there's obviously no image. How to do this?
NSData *photoData = [[[self appDelegate] xmppvCardAvatarModule]photoDataForJID:user.jid];
UIImageView *picVista;
picVista.image = [UIImage imageWithData:photoData];
try this it works fine for me
Below is the method I'm using with Sharekit to send an image and a title to facebook. I also want to send a URL along with the facebook post. If I try
SHKItem *item = [SHKItem image:image url:url title:titleString];
I get a too many arguments error message. Does anyone have any ideas on how this should be done? thanks for any help.
- (IBAction)myButtonHandlerAction
{
NSURL *url = [NSURL URLWithString:#"http://example.com/"];
NSString *titleString = [[NSString alloc] initWithFormat:#"*** %# * \n\nGet the ***** App - It's Free!", entity.name];
UIImage *image = [[[UIImage alloc] initWithData:entity.image] autorelease];
SHKItem *item = [SHKItem image:image title:titleString];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showFromBarButtonItem:barbtn animated:YES];
}
There is no method -[SHKItem image:url:title:]. So an error is being raised. Currently there is no mechanism to do what you require using ShareKit so you will have to customize ShareKit for your needs. You should also look at the Graph API.
Maybe what you want is a url item, with an image attached to it. If so, you can do this :
SHKItem *item = [SHKItem URL:[NSURL URLWithString:#"http://example.com/"] title:#"Check this link"];
[item setCustomValue:#"http://example.com/someimage.jpg" forKey:#"picture"];
[SHKFacebook shareItem:item];
I've implemented this with the latest sharekit, it works for me.