How to Get OAuth Access Token for Pinterest?

被刻印的时光 ゝ 提交于 2019-11-28 03:23:25

问题


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?


回答1:


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?




回答2:


You need to register a client app under manager Apps option in Dropdown menu when you login

or

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

Register your app and you get AppID.

This follow the process in this link you have

http://wiki.gic.mx/pinterest-developers/

Hope this helps




回答3:


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



来源:https://stackoverflow.com/questions/21455388/how-to-get-oauth-access-token-for-pinterest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!