Sign in with pinterest on iOS

There is an explanation for the output to Pinterest for developers .

But I still have the following two questions:

  • How to enter?
  • How to get a registered user response from the server after logging in?

I went through all the demos available on google and the stack overflow, they all explain using a web view . but using the web view, we can’t get a response from the user's login, and in some demos they explained only how to fix it?

In my application, I want to log in using pinterest.

Any help with questions would be greatly appreciated.

+4
source share
3 answers

The SDK provided by Pinterest has Assign it as described on their developer's website. You cannot log in with this SDK, but you can associate images with it.

Pinterest does not have an official login API, but they use the OAuth2 protocol. Therefore, you may have to write your own UIWebView handler that allows you to register. This will require researching the OAuth2 protocol and storing cookies. Not a very simple task.

Mark this GitHub project for a starting point.

:

+1

SDK, Pinterest. , . Pinterest 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://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://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;
}

- (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

1 4

Appdelgate.swift :

import PinterestSDK

didFinishLaunchingWithOptions appdelegate

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

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()
}
0

Source: https://habr.com/ru/post/1531766/


All Articles