iOS应用程序与pinterest的集成

时间:2012-03-28 14:22:06

标签: iphone objective-c ios pinterest

目前允许来自iOS应用的pinterest共享的最强可靠方式是什么?

Pinterest API尚未公开,只有建议的分享方式是他们的网络按钮。

5 个答案:

答案 0 :(得分:11)

我在我的iPad应用程序中进行了最好的集成。但是,因为Pinterest还没有用于发布的API,所以我使用了以下方法。我只是以编程方式创建一个HTML网页,并以编程方式将Pin it按钮添加到该页面。然后我显示一个Web视图,并允许用户再次单击Pin it。这些是更多解释的步骤。

1)创建一个具有UIWebView的WebViewController。添加关闭按钮,添加UIWebViewDelegateProtocol,spinner,htmlString属性。

2)当用户点击你的应用中的“Pin it”按钮时,以编程方式生成HTML以放入UIWebView。在这种情况下,我为不同的产品添加了不同的图像的HTML页面。

- (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\"><a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></a></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;
}

这是我的HTML页面生成方法的一个示例。

3)创建一个方法,当用户点击“Pin it”按钮时调用该方法,该按钮显示带有图像的webView,您将发布的UIWebView上的“Pin it”按钮。这是我的例子:

- (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)将“关闭”按钮放到WebViewController上以关闭它。您还可以添加微调器来跟踪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。我使用相同的方法将Google Plus的+1按钮添加到iPad应用中。 (它也没有发布API,目前只有readonly API)

答案 1 :(得分:5)

如果您只想共享(即在用户板上固定),那么您可以使用iphone-URL-Scheme并调用Pinterest应用程序以及参数 url (页面的URL到pin),媒体(图片的网址为pin)&amp; 说明(要固定的页面说明)。如果用户尚未安装,请提供UIAlertView并将其转发到appstore以下载官方Pinterest应用程序。

<强>参考http://wiki.akosma.com/IPhone_URL_Schemes#Pinterest

打开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方法

- (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];
    }
}

答案 2 :(得分:2)

我看起来又高又低。我甚至联系了Pinterest团队关于SDK的问题。我发现最接近的是github https://github.com/kellan/pinterest.api.php上的PHP包装器。

这不是最好的解决方案,因为它是非正式的api,很可能会破坏。

答案 3 :(得分:2)

截至2013年5月20日,Pinterest发布了用于固定内容的iOS SDK。

查看their Developers site了解详情。

答案 4 :(得分:0)

我尝试将Pinterest与自定义URL方案集成,也可以在我的设备上下载Pinterest应用程序,但不能与它集成。

问题是我不想使用webView进行集成,所以有可能这样做,我没有在应用程序商店找到任何具有最佳集成的应用程序。

我也谷歌搜索,但更糟糕的是,Snapguide还删除了他们应用程序的最佳集成。

我使用了webView代码来固定图像,无需打开完整的Pinterest网站,

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"];

这很容易但是使用webView并且我不想要。