Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get OAuth Access Token for Pinterest?

Tags:

pinterest

I am accessing Pinterest API for getting user's information by using this url but I can not find that how to generate an access token for Pinterest.

According to this blog post, it says that

Pinterest uses OAuth2 to authenticate users

Can you please tell me, from where I can generate OAuth access tokens for Pinterest?

like image 212
Dhruv Avatar asked Jan 30 '14 11:01

Dhruv


People also ask

How do I get a Pinterest Access Token?

In order for you to get an Access Token now you will need to be the owner or have the owner of the Pinterest feed you want to show, click the button on the Pinterest Options page of our plugin to get there Access Token. Most importantly, click the Save all changes button at the bottom of the page to save the token.

How can I get my OAuth token?

To get a token for a Server Application client, make a POST request to the Panopto Oauth2 token endpoint. The post request should be sent with a content type of x-www-form-urlencoded, and include the following parameters: grant_type: The method you are using to get a token.

How can I get Access Token using authorization code?

To get a new access token, use the refresh token as you would an authorization code, but with a grant_type value of refresh_token and a refresh_token parameter that holds the contents of the refresh token. The type of grant being used. To exchange a refresh token for an access token, use refresh_token .


2 Answers

**USING C#**

public string GetOAuthToken(string data)
    {
        string strResult = string.Empty;
        try
        {
                string Clientid = WebConfigurationManager.AppSettings["Pinterest_Clientid"];
                string ClientSecret = WebConfigurationManager.AppSettings["Pinterest_ClientSecret"];
                string uri_token = WebConfigurationManager.AppSettings["Pinterest_Uri_Token"];
                System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri_token);

                string parameters = "grant_type=authorization_code"
                                    + "&client_id="
                                    + Clientid
                                    + "&client_secret="
                                    + ClientSecret
                                    + "&code="
                                    + data;

                req.ContentType = "application/x-www-form-urlencoded";
                req.Method = "POST";
                byte[] bytes = Encoding.ASCII.GetBytes(parameters);
                System.IO.Stream os = null;
                req.ContentLength = bytes.Length;
                os = req.GetRequestStream();
                os.Write(bytes, 0, bytes.Length);
                System.Net.WebResponse webResponse = req.GetResponse();
                System.IO.Stream stream = webResponse.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(stream);
                string response = reader.ReadToEnd();
                Newtonsoft.Json.Linq.JObject o = Newtonsoft.Json.Linq.JObject.Parse(response);
                strResult = "SUCCESS:" + o["access_token"].ToString();                    
        }
        catch (Exception ex)
        {
            strResult = "ERROR:" + ex.Message.ToString();
        }
        return strResult;
    }

Refer

like image 143
Mohan Kumar Avatar answered Sep 17 '22 19:09

Mohan Kumar


First, register for an app and set up a redirect URI:

https://developers.pinterest.com/manage/

Then, find your client secret under Signature Tester:

https://developers.pinterest.com/tools/signature/

Bring the user to the OAuth dialog like this:

https://www.pinterest.com/oauth/?consumer_id=[client_id]&response_type=[code_or_token]&scope=[list_of_scopes]

If response type if token, it will be appended as a hash in the redirect URI.

If response type is code, see the post below for details on how to exchange code for token:

What's the auth code endpoint in Pinterest?

like image 35
Ben Wong Avatar answered Sep 19 '22 19:09

Ben Wong