20

現在、iOS アプリから pinterest の共有を許可する最も信頼できる方法は何ですか?

Pinterest API はまだ公開されておらず、共有する唯一の推奨される方法は Web ボタンです。

4

5 に答える 5

11

iPad アプリに pinterest を統合しました。しかし、Pinterest にはまだ投稿用の API がないため、次の方法を使用しました。プログラムで HTML Web ページを作成し、プログラムでそのページに [ピン留め] ボタンを追加するだけです。次に、Web ビューを表示し、ユーザーが [ピン留め] をもう一度クリックできるようにします。これらは、より説明された手順です。

1) UIWebView を持つ WebViewController を作成します。閉じるボタンを追加、UIWebViewDelegateProtocol、spinner、htmlString プロパティを追加。

2)ユーザーがアプリの「ピン留め」ボタンをクリックすると、そのUIWebViewに配置するHTMLをプログラムで生成します。この場合、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)ユーザーが「ピン留め」ボタンをタップしたときに呼び出すメソッドを作成します。これにより、投稿する画像とその webView が表示され、UIWebView の「ピン留め」ボタンが表示されます。これは私の例です:

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

PS 同じ方法で、Google Plus の +1 ボタンを iPad アプリに追加しました。(投稿APIもありません。現時点では読み取り専用APIのみです)

于 2012-05-16T12:26:28.600 に答える
5

共有するだけ (つまり、ユーザー ボードにピン留め) する場合は、iphone-URL-Scheme を使用して、パラメータurl (ピン留めするページの URL)、 メディア(ピン留めする画像の URL ) と共に Pinterest アプリケーションを呼び出すことができます。 pin) & description (ピン留めするページの説明)。ユーザーがインストールしていない場合は、UIAlertView を提示して appstore に転送し、公式の Pinterest アプリケーションをダウンロードします。

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

Pinterest アプリケーションを開くコード:

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];
    }
}
于 2012-07-23T17:17:40.613 に答える
2

2013 年 5 月 20 日の時点で、Pinterest はコンテンツを固定するための iOS SDK をリリースしました。

詳細については、開発者サイトをご覧ください。

于 2013-05-22T09:37:52.887 に答える
2

私も高低を見てきました。SDK について Pinterest チームに連絡したこともあります。私が見つけた最も近いものは、github https://github.com/kellan/pinterest.api.phpの PHP ラッパーです。

ただし、これは非公式の API であり、壊れる可能性が高いため、最善の解決策ではありません。

于 2012-03-28T15:38:37.120 に答える
0

Pinterest をカスタム URL スキームと統合しようとしました。また、Pinterest アプリケーションをデバイスにダウンロードしましたが、統合することはできませんでした。

そして、私は統合にwebViewを使用したくないので、それを行うことは可能ですか?私はピンタレスト統合を持つアプリケーションをアプリストアで見つけられませんでした.

私もグーグルで調べましたが、さらに悪いことに、Snapguide もアプリケーションから pinterest 統合を削除しました。

画像をピン留めするために webView コードを使用しました。Pinterest の完全な Web サイトを開く必要はありません。

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 を使用すると、私はしたくありません。

于 2012-10-15T09:37:48.747 に答える