Search code examples
iossdkpinterest

Post to Pinterest from an iOS app without leaving the app?


I successfully integrated the Pinterest iOS SDK and can pin items, but it takes the user out of the app. Is there a way to do this but stay within the app?

I followed this guide already (How to integrate Pinterest in ios application)


Solution

  • Yes you can pin items without leaving your app. It is mentioned in other answers, Pinterest has no official API. However their original web site using HTTP POST methods and you can do same thing programatically with using NSURLRequest and NSURLConnection or any other wrappers as like AFNetworking.

    It is kinda hacky way but since they have no API this is the only way to do it. Only the downside, if they change something on their site code you should update your code regarding. I have released a OS X application couple months back, it is working fine since then.

    I would like to write everything down here however it is almost complete application, this why I have prepared a sample app for you. If you decide to use this you have to tidy up the code little bit. You can download sample project from GitHub

    How it works: Basically you have to login to Pinterest with using UIWebView, once you logged in UIWebView write cookies, we are going to use those cookies in HTTP headers to authenticate. (If you want to support social media logins you have to implement those separately)

    Once we have the cookie, first thing first getting board list. -(void)getBoardList, then next step is choosing the board which you want to pin (you have to implement this, for now it show up 1st board in the list).

    Pinning is two step operation here, At the first step you need to upload image to storage of Pinterest which -(IBAction)uploadImage:(id)sender method handles it. If image upload success it automatically call -(void)pinImage:(NSString *)imageURL to register your image to the selected board.

    When you review the code you will see all variables hardcoded, you have to implement all of them as well. As I said this is at least gives you the idea how you can pin image to Pinterest. There is not error control in the code as well. while trying if you don't have any board, probably it will throw and error.