0

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

 //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! 的在线服务列表。此外,如果您尝试在下面搜索,您可能会找到您要查找的内容。

4

1 回答 1

0

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

于 2013-03-05T18:30:38.027 回答