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

时间:2014-01-30 11:36:13

标签: pinterest

我正在使用此url访问Pinterest API以获取用户信息,但我找不到如何为Pinterest生成访问令牌。

根据这个blog post,它说

  

Pinterest使用OAuth2对用户进行身份验证

请告诉我,我可以从哪里为Pinterest生成OAuth访问令牌?

3 个答案:

答案 0 :(得分:7)

首先,注册一个应用并设置重定向URI:

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

然后,在Signature Tester下找到您的客户机密码:

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]

如果是令牌的响应类型,则它将作为重定向URI中的哈希附加。

如果响应类型是代码,请参阅下面的帖子,了解有关如何交换令牌代码的详细信息:

What's the auth code endpoint in Pinterest?

答案 1 :(得分:3)

登录时,您需要在下拉菜单中的经理应用选项下注册客户端应用

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

注册您的应用,即可获得AppID。

这遵循此链接中的过程

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

希望这有帮助

答案 2 :(得分:1)

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