【问题标题】:Is this the correct way to obtain the access token这是获取访问令牌的正确方法吗
【发布时间】:2013-03-05 18:27:55
【问题描述】:

我设法获得了请求令牌,但我无法获得访问令牌。我获取访问令牌的方式是否正确。有什么建议吗?

 //Step : 1 (Returns Request Token)
string consumer_key = "dj0yJmk9bl..........lRReU9UWXkmcz1jb25zdW1lcnNlY3JldCZ4PWIy";
string username = "some_user";
string pass = "some_pass";
string url = "https://login.yahoo.com/WSLogin/V1/get_auth_token?&login="+username+"&passwd="+pass+"&oauth_consumer_key="+consumer_key;

HttpWebRequest request_a = (HttpWebRequest)WebRequest.Create(url);
Stream objStream;
objStream = request_a.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
string resp = objReader.ReadLine(); //Since first line has the response - "Returns RequestToken=jUO3Qolu3AYGU1KtB9vUbxlnzfIiFRLP.."
string requesttoken = resp.Replace("RequestToken=", "");

//Step : 2 (Returns OAuth access token)
string auth_ = "&Authorization=OAuth";
string realm = "&realm=yahooapis.com";
string oauth_consumer_key = "&oauth_consumer_key=dj0yJmk9....bzlNVEV4TlRReU9UWXkmcz1jb25zdW1lcnNlY3JldCZ4PWIy"; //This is Consumer Key
string oauth_nonce = "&oauth_nonce=24829.2331";
string oauth_signature_method = "&oauth_signature_method=PLAINTEXT";
string tstamp = "&oauth_timestamp=1219450170";
string oauth_token = "&oauth_token="+ requesttoken; //
string oauth_version = "&oauth_version=1.0";
string oauth_signat = "&oauth_signature=cbbe4eacb0c171ee9a78c070d2095a86dcc2b6ba"; // This is the Consumer Secret
string new_url = "https://api.login.yahoo.com/oauth/v2/get_token?";
string command = new_url + auth_ + realm + oauth_consumer_key + oauth_nonce + oauth_signature_method + tstamp + oauth_token + oauth_version + oauth_signat;

HttpWebRequest request_b = (HttpWebRequest)WebRequest.Create(command);
Stream objStream_b;
objStream_b = request_a.GetResponse().GetResponseStream();
StreamReader objReader_b = new StreamReader(objStream);

我尝试在 webbrowser 中测试命令变量,得到以下结果

抱歉,禁止访问:您无权访问此服务器上的此 URL。

请检查 URL 的拼写和大小写是否正确。如果您在 Yahoo! 上查找目的地时遇到问题,请尝试访问 Yahoo!主页或浏览 Yahoo! 的在线服务列表。此外,如果您尝试在下面搜索,您可能会找到您要查找的内容。

【问题讨论】:

  • 您缺少using 语句和try-catch 块。

标签: c# access-token http-status-code-403 yahoo-api


【解决方案1】:

oauth_signat 的开头没有&...我不知道 yahoo api 但这个string auth_ = "&Authorization: OAuth"; 应该是这个string auth_ = "&Authorization=OAuth";

【讨论】:

  • 我刚刚添加了 & 但我仍然收到该错误。还将 : 更改为 =
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-15
  • 1970-01-01
  • 2020-11-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多