如何获取Pinterest的OAuth访问令牌?

11
我正在访问Pinterest API,使用此网址获取用户信息,但我无法找到如何为Pinterest生成访问令牌的方法。
根据这篇博客文章所说:

Pinterest使用OAuth2来验证用户

请问您能告诉我在哪里为Pinterest生成OAuth访问令牌吗?
4个回答

8

首先,注册应用程序并设置重定向URI:

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

然后,在签名测试器下找到客户端密钥:

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

像这样将用户带到OAuth对话框:

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

如果响应类型为token,则会将其附加为重定向URI中的哈希值。

如果响应类型为code,请参阅下面的文章了解如何交换代码以获取令牌的详细信息:

Pinterest的授权代码端点是什么?


我想使用 https://www.pinterest.com/oauth/ 进行授权,请帮忙。以下是我的链接:https://pinterest.com/oauth/?consumer_id=4944452830850198488&redirect_uri=https%3A%2F%2Ftest.xxxxxx.com%2Fconnectpinterestboardapi&response_type=code&state=121213131312大家好,我的上述链接无法工作。我们需要进行哪种类型的额外代码?应用程序 ID 是否等同于消费者 ID?如果不是,那么我何时可以获得消费者 ID?而且我的消费者 ID(应用程序 ID)比你们的多几位数字。大家帮帮我。 - Ankur Patel

4

你如何获取client_secret?它在仪表板上没有显示。 - Eugenio Pace
1
在那个页面上有一个“签名测试器”的选项,一旦你点击进去,你就会看到客户端密钥。 - Sambhav Sharma

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


点赞。Pinterest POS API将参数显示为查询参数,而不是表单元素,这让我花费了数小时的时间来梳理头发,直到我看到了你的帖子。 - Abhijit Sarkar

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接