The remote server returned an error: (401) Unauthorized.
i am developing an application, which require to import a contact, so plz help me
i have got consumer key and secret key, but i m unable to find "oauth_token" and "oauth_verifier" code so please tell me how to do this.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string oauth_token = Request["oauth_token"];
string oauth_verifier = Request["oauth_verifier"];
if (!string.IsNullOrEmpty(oauth_verifier) && oauth_verifier != "")
{
Button1.Visible = false;
OauthToken = oauth_token;
OauthVerifier = oauth_verifier;
RegisterStartupScript("refresh", "<script type='text/javascript'>window.opener.location = 'oauth-test.aspx'; self.close();</script>");
}
}
private string GetRequestToken()
{
string authorizationUrl = string.Empty;
OAuthBase oauth = new OAuthBase();
Uri uri = new Uri("https://api.login.yahoo.com/oauth/v2/get_request_token");
string nonce = oauth.GenerateNonce();
string timeStamp = oauth.GenerateTimeStamp();
string normalizedUrl;
string normalizedRequestParameters;
string sig = oauth.GenerateSignature(uri, ConsumerKey, ConsumerSecret, string.Empty, string.Empty, "GET", timeStamp, nonce, OAuthBase.SignatureTypes.PLAINTEXT, out normalizedUrl, out normalizedRequestParameters); //OAuthBase.SignatureTypes.HMACSHA1
StringBuilder sbRequestToken = new StringBuilder(uri.ToString());
sbRequestToken.AppendFormat("?oauth_nonce={0}&", nonce);
sbRequestToken.AppendFormat("oauth_timestamp={0}&", timeStamp);
sbRequestToken.AppendFormat("oauth_consumer_key={0}&", ConsumerKey);
sbRequestToken.AppendFormat("oauth_signature_method={0}&", "PLAINTEXT"); //HMAC-SHA1
sbRequestToken.AppendFormat("oauth_signature={0}&", sig);
sbRequestToken.AppendFormat("oauth_version={0}&", "1.0");
sbRequestToken.AppendFormat("oauth_callback={0}", HttpUtility.UrlEncode("http://localhost:3959/OAuth-yahoo/oauth-test.aspx"));
//Response.Write(sbRequestToken.ToString());
//Response.End();
try
{
string returnStr = string.Empty;
string[] returnData;
Response.Write(ex.Message);
}
}
private void RetriveContacts()
{
OAuthBase oauth = new OAuthBase();
Uri uri = new Uri("http://social.yahooapis.com/v1/user/" + OauthYahooGuid + "/contacts?format=XML");
string nonce = oauth.GenerateNonce();
string timeStamp = oauth.GenerateTimeStamp();
protected void Button1_Click(object sender, EventArgs e)
{
string authorizationUrl = string.Empty;
authorizationUrl = GetRequestToken();
RedirectUserForAuthorization(authorizationUrl);