【发布时间】:2016-07-20 15:00:10
【问题描述】:
我正在访问 Pinterest API 以使用此 url 获取用户信息,但我找不到如何为 Pinterest 生成访问令牌。
根据这个blog post,它说
Pinterest 使用 OAuth2 对用户进行身份验证
您能否告诉我,我可以从哪里为 Pinterest 生成 OAuth 访问令牌?
【问题讨论】:
标签: pinterest
我正在访问 Pinterest API 以使用此 url 获取用户信息,但我找不到如何为 Pinterest 生成访问令牌。
根据这个blog post,它说
Pinterest 使用 OAuth2 对用户进行身份验证
您能否告诉我,我可以从哪里为 Pinterest 生成 OAuth 访问令牌?
【问题讨论】:
标签: pinterest
首先,注册一个应用并设置一个重定向URI:
https://developers.pinterest.com/manage/
然后,在 Signature Tester 下找到您的客户端密码:
https://developers.pinterest.com/tools/signature/
像这样将用户带到 OAuth 对话框:
如果响应类型为令牌,它将作为哈希附加在重定向 URI 中。
如果响应类型是代码,请参阅下面的帖子了解如何将代码交换为令牌:
【讨论】:
您需要在登录时在下拉菜单的管理器应用选项下注册一个客户端应用
或
https://developers.pinterest.com/manage/
注册您的应用,您将获得 AppID。
这遵循这个链接中的过程你有
http://wiki.gic.mx/pinterest-developers/
希望对你有帮助
【讨论】:
**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;
}
【讨论】: