我设法获取请求令牌但我无法获得访问令牌。我是否正确获取访问令牌。有什么建议吗?
//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中测试命令变量,然后得到以下内容
抱歉,禁止访问:您无权在此服务器上访问此网址。
请检查网址是否有正确的拼写和大小写。如果您在Yahoo!上找到目的地时遇到问题,请尝试访问Yahoo!主页或查看Yahoo!的在线服务列表。此外,如果您尝试在下面搜索,也可以找到您要找的内容。
答案 0 :(得分:0)
oauth_signat开头没有&
...我不知道yahoo api但是string auth_ = "&Authorization: OAuth";
应该是string auth_ = "&Authorization=OAuth";