I can easy implement log in with facebook on iPhone. But I heared, that there was no official API for pinterest.
So I wonder if there is a way to implement login with Pinterest. So my app can identify user after his login with pinterest.
Without an official Pinterest public API, anything else you write to be some kind of workaround is likely to break very easily. Best to register with Pintrist directly and hopefully they'll seed you with access to a beta SDK or API, once they come up with it.
That said, there appears to be some stuff potentially available but not sure what the current status is.
Pintrest uses oAuth2 you should be able to use it akin of all the other providers ie GET request to a certain url to obtain the token, step by step instructions can be found here
http://tijn.bo.lt/pinterest-api
OAuth2 is an official api the issue boils down to finding the endpoint and GET syntax
One thing to note is the object that is being returned can contain different values accross providers for instance I needed a Twitter and FB solution, but Twitter doesn't give you user's email so you had to ask for it separately (to uniquely identify the same account accross providers)
For ruby there's the omniauth gem that lets you use multiple providers (strategies) with ease. Shouldn't be to complicated to roll out your own solution for or find a library for IOS
Hi there is no official api for Pinterest, But Here is a link already answered
or try like this, create button with the following target
[pintrestBtn addTarget:self action:#selector(pintrestButtonSelcted) forControlEvents:UIControlEventTouchUpInside]
and push when the htmlstring comes as perfect url push it to another viewcontroller which has webview and load this htmlstring in that webview
- (void) pintrestButtonSelcted {
NSString *htmlString = [self generatePinterestHTMLForSKU:nil];
NSLog(#"Generated HTML String:%#", htmlString);
WebViewController *webViewController = [[WebViewController alloc] init];
webViewController.htmlString = htmlString;
webViewController.view.frame = CGRectMake(0, 0, 300, 300);
[self presentModalViewController:webViewController animated:YES];
}
- (NSString*) generatePinterestHTMLForSKU:(NSString*)sku {
NSString *description = #"Post your description here";
// Generate urls for button and image
NSString *sUrl = [NSString stringWithFormat:#"http://reedperry.com/2011/04/27/apple-logo/"];
NSLog(#"URL:%#", sUrl);
NSString *protectedUrl = ( NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,( CFStringRef)sUrl, NULL, (CFStringRef)#"!*'\"();:#&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
NSLog(#"Protected URL:%#", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:#"\"%#\"", sUrl];
NSString *buttonUrl = [NSString stringWithFormat:#"\"http://pinterest.com/pin/create/button/?url=http://itunes.apple.com/us/app/pinterest/id429047995?mt=8&media=http://reedperry.com/2011/04/27/apple-logo/%#&description=Welcome you all%#\"", protectedUrl, description];
NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
[htmlString appendFormat:#"<html> <body>"];
[htmlString appendFormat:#"<p align=\"center\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></p>", buttonUrl];
[htmlString appendFormat:#"<p align=\"center\"><img width=\"400px\" height = \"400px\" src=%#></img></p>", imageUrl];
[htmlString appendFormat:#"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"];
[htmlString appendFormat:#"</body> </html>"];
return htmlString;
}
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
What is the most reliable way currently to allow pinterest sharing from iOS app?
Pinterest API is not public yet and only suggested way to share is their web button.
I made a pinterest integration in my iPad app. But, because Pinterest doesn't have an API for posting yet, I used the following method. I just create programmatically an HTML Web Page and add a Pin it button to that page programmatically. Then I show a Web View and allow user to click Pin it once more. These are more explained steps.
1) Create a WebViewController, that has a UIWebView. Add Close button, add UIWebViewDelegateProtocol, spinner, htmlString property.
2) Generate an HTML programmatically to put to that UIWebView, when user clicks your "Pin it" button in your app. In this case I put to the HTML page different images for different products.
- (NSString*) generatePinterestHTMLForSKU:(NSString*)sku {
NSString *description = #"Post your description here";
// Generate urls for button and image
NSString *sUrl = [NSString stringWithFormat:#"http://d30t6wl9ttrlhf.cloudfront.net/media/catalog/product/Heros/%#-1.jpg", sku];
NSLog(#"URL:%#", sUrl);
NSString *protectedUrl = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef)sUrl, NULL, (CFStringRef)#"!*'\"();:#&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
NSLog(#"Protected URL:%#", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:#"\"%#\"", sUrl];
NSString *buttonUrl = [NSString stringWithFormat:#"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%#&description=%#\"", protectedUrl, description];
NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
[htmlString appendFormat:#"<html> <body>"];
[htmlString appendFormat:#"<p align=\"center\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></p>", buttonUrl];
[htmlString appendFormat:#"<p align=\"center\"><img width=\"400px\" height = \"400px\" src=%#></img></p>", imageUrl];
[htmlString appendFormat:#"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"];
[htmlString appendFormat:#"</body> </html>"];
return htmlString;
}
This is an example of my HTML page generation method.
3) Create a method to call when user taps your "Pin it" button, which shows that webView with the image, that you will post and the "Pin it" button on the UIWebView. This is my example:
- (void) postToPinterest {
NSString *htmlString = [self generatePinterestHTMLForSKU:self.flProduct.sku];
NSLog(#"Generated HTML String:%#", htmlString);
WebViewController *webViewController = [[WebViewController alloc] initWithNibName:#"WebViewController" bundle:nil];
webViewController.htmlString = htmlString;
webViewController.showSpinner = YES;
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:webViewController animated:YES];
}
4) Put a "Close" button to your WebViewController to close it. Also you can add spinners to track the loading of the UIWebView.
- (IBAction)closeClicked:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
if (showSpinner) {
// If we want to show Spinner, we show it everyTime
[UIHelper startShowingSpinner:self.webView];
}
else {
// If we don't -> we show it only once (some sites annoy with it)
if (!spinnerWasShown) {
[UIHelper startShowingSpinner:self.webView];
spinnerWasShown = YES;
}
}
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[UIHelper stopShowingSpinner];
}
P.S. I used the same method to add Google Plus's +1 button to the iPad app. (It doesn't have posting API too, only readonly API at the moment)
If you only want to share(i.e. pin on a user board), then you can use iphone-URL-Scheme and call the Pinterest application along with the parameters url(URL of the page to pin), media(URL of the image to pin) & description(Description of the page to be pinned). Present a UIAlertView and forward them to appstore to download the official Pinterest application if the user has not installed it.
Reference:
http://wiki.akosma.com/IPhone_URL_Schemes#Pinterest
Code to open Pinterest Applicaiton:
NSURL *url = [NSURL URLWithString:#"pinit12://pinterest.com/pin/create/bookmarklet/?url=URL-OF-THE-PAGE-TO-PIN&media=URL-OF-THE-IMAGE-TO-PIN&description=ENTER-YOUR-DESCRIPTION-FOR-THE-PIN"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Pinterest" message:#"Would you like to download Pinterest Application to share?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Continue", nil];
[alert show];
}
UIAlertViewDelegate Method
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1){
NSString *stringURL = #"http://itunes.apple.com/us/app/pinterest/id429047995?mt=8";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
}
As of May 20th 2013, Pinterest have released an iOS SDK for pinning content.
Check out their Developers site for more information.
I've looked high and low too. I've even contacted Pinterest Team about an SDK. The closest thing I have found is a PHP wrapper on github https://github.com/kellan/pinterest.api.php.
It's not the best solution though because it is unofficial api and will most likely break.
I tried to integrate Pinterest with Custom URL Scheme, also download the Pinterest application on my device, but not abel to integrate with it.
And the thing is that i don't want to used webView for integration so is it possible to do that, i didn't found any application on app store which have pinterest integration.
I did googling also but all worse, Snapguide also remove pinterest integration from their application.
I used a webView code to pin image , no need to open full Pinterest website,
NSString *urlStr =[NSString stringWithFormat:#"http://pinterest.com/pin/create/bookmarklet/?url=www.<domainname>.com&media=http://<domainname>.files.com/hello.jpg?w=495&description=hello"];
This would be easy but with webView and that i don't want.
- (void)postToWall {
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = [NSString stringWithFormat: subjectTitle]; //subjectTitle works here but not as name where i need it.
NSString *src = #"http://www.sample.com/image.png";
NSString *name = storyLink; //<---------------------------------works with storyLink but not subjectTitle. I need subjectTitle to work here
NSString *href = storyLink;
NSString *attachment = [NSString stringWithFormat:#"{\"name\":\"%#\",\"media\":[{\"type\":\"image\", \"src\":\"%#\", \"href\":\"%#\"}]}", name, src, href];
dialog.attachment = attachment;
[dialog show];
}
i want to add image from photo library instred of http://www.sample.com/image.png to the facebook wall.
can anyone provides me help ....
Thanks in advance ......
You can access the URL's of the iPhoto library items using the UIImagePickerController and its delegate method.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
When the user picks a photo the URL will be in the dictionary under the key UIImagePickerControllerMediaURL
Probably this Stack Overflow Question about uploading images to Facebook might help you.
Also Sharekit is a nice framework to add Social features to you iPhone App. I think it has facility to share images. You can check it out at Sharekit official website.
I want to send message with image data. So I used MFMessageComposeViewController.
But that controller provide only SMS service. So I used UIPasteBoard attached an image data.
But It doesn't work, either. There are no "Paste" button created when typing messages. Attaching image at UIPasteBoard was clearly success.
I think using MFMessageComposeViewController doesn't solve my problem.
How can I accomplish my goal?
This is not possible with the current MessageUI API: the MSMessageComposeViewController doesn't accept attachments like the MFMailComposeViewController does.
The only way to do this currently is to use an external service that allows you to send mms via a REST call for example.
GSMA defines a REST specification for exactly this purpose:
http://www.gsmworld.com/oneapi/reference_documentation-version_1.html (multiple pdf's on this page)
Try to find a local service provider that implements this specification and you're good to go.
Just to add the direct wiki link to the OneAPI MMS spec: http://gsma.securespsite.com/access/Access%20API%20Wiki/MMS%20RESTful%20API.aspx and a link to the PHP/Java sandbox https://github.com/OneAPI/GSMA-OneAPI where MMS can be tested locally . Cheers.
Here is the correct working code and it is working perfectly on my device.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = NO;
NSMutableDictionary *text = [NSMutableDictionary dictionaryWithCapacity:1];
[text setValue:label.text forKey:(NSString *)kUTTypeUTF8PlainText];
NSMutableDictionary *image = [NSMutableDictionary dictionaryWithCapacity:1];
[image setValue:imageView.image forKey:(NSString *)kUTTypePNG];
pasteboard.items = [NSArray arrayWithObjects:image,text, nil];
NSString *phoneToCall = #"sms:";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
I had the same question that I posted here. There is a bug in MFMessageComposeViewController and if you just use the code below it will launch a message that you can insert images into
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
This Method is tested and verified. I Used it in my code.
if (![MFMessageComposeViewController canSendText]) {
UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device not support SMS \nOr you hadn't login your iMessage" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertV show];
return;
}
MFMessageComposeViewController *mVC = [[MFMessageComposeViewController alloc] init];
mVC.body = #"jjjj";
mVC.recipients = #[#"00XXXXXXXXXX"];
mVC.messageComposeDelegate = self;
if ([MFMessageComposeViewController canSendAttachments]) {
NSLog(#"ok");
}
[mVC addAttachmentData: UIImageJPEGRepresentation([UIImage imageNamed:#"test.jpg"], 1.0) typeIdentifier:#"public.data" filename:#"image.jpeg"];
[self presentViewController:mVC animated:YES completion:nil];
You can use any jpeg jpg and png formats.
Swift way. Works in iOS11
func shareViaMessage() {
if !MFMessageComposeViewController.canSendText() {
showAlert("Text services are not available")
return
}
let textComposer = MFMessageComposeViewController()
textComposer.messageComposeDelegate = self
textComposer.body = "Try my #app"
if MFMessageComposeViewController.canSendSubject() {
textComposer.subject = "AppName"
}
if MFMessageComposeViewController.canSendAttachments() {
let imageData = UIImageJPEGRepresentation(imageView.image!, 1.0)
textComposer.addAttachmentData(imageData!, typeIdentifier: "image/jpg", filename: "photo.jpg")
}
present(textComposer, animated: true)
}
Why don't you share the Image and Text via the Share API (selecting Message, and if you want exluding Facebook, twitter etc..)
I am making an iphone game , In that I want to upload score on face book. I am new to face book codes, I've got it's API from github.com. But I don't know how to write or post directly my message on wall of face book of log in account else how to share my score on facebook. I've done log in portion.
Can any one help me????
Please refer the facebook api development at http://wiki.developers.facebook.com/index.php/Facebook_iPhone_SDK
Sample application also given by facebook for iPhone.
Thanks,
Jim.
Assuming the user has allready logged in and you have a vaild faceb0ok session, you could use something like this to get you started:
- (void) post {
postingDialog = [[[FBStreamDialog alloc] init] autorelease];
postingDialog.delegate = self;
postingDialog.userMessagePrompt = #"Prompt the User:";
NSString *name = #"Name of thing"
NSString *href = #"http://www.example.com"
NSString *caption = #"This is a caption"
NSString *description = #"This is a description";
NSString *imageSource = #"http://example.com/1.png";
NSString *imageHref = #"http://example.com/1.png";
NSString *linkTitle = #"Link title";
NSString *linkText = #"Text";
NSString *linkHref = #"http://www.example.com/iphone";
postingDialog.attachment = [NSString stringWithFormat:
#"{ \"name\":\"%#\","
"\"href\":\"%#\","
"\"caption\":\"%#\",\"description\":\"%#\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"%#\","
"\"href\":\"%#\"}],"
"\"properties\":{\"%#\":{\"text\":\"%#\",\"href\":\"%#\"}}}", name, href, caption, description, imageSource, imageHref, linkTitle, linkText, linkHref];
[postingDialog show];
}
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];