Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hello

Below is the code I am using using for Twitter login.
But it generates the errors:
No overload for method 'GetAccessToken' takes 3 arguments
and
No overload for method 'GetRequestToken' takes 2 arguments

When I used like this
C#
OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret);

then it shows the error
C#
Cannot implicitly convert type 'Twitterizer.OAuthTokenResponse' to 'OAuthTokenResponse'

C#
protected void imgbtnTwitter_Click(object sender, ImageClickEventArgs e)
{
	//  bool condition = forceLoginCheckbox.Checked;
	//TwitterConsumer.StartSignInWithTwitter(condition).Send();
	// add these to web.config or your preferred location
	var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
	var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

	if (Request.QueryString["oauth_token"] == null)
	{
		//Step 1: Get Request Token
		OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret);

		//Step 2: Redirect User to Requested Token
		Response.Redirect("http://twitter.com/oauth/authorize?oauth_token=" + RequestToken.Token);
	}
	else
	{
		//For Valid User
		string Oauth_Token = Request.QueryString["oauth_token"].ToString();

		var accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, Oauth_Token);
	}
}


Can anyone suggest better method for login with twitter.

Thanks,
Deepak
Posted
Updated 1-Oct-11 11:26am
v2

1 solution

Your first two errors are because you have passed too much or not enough arguments to GetRequestToken or GetAccessToken - look at how many they take! (If you can't work out what those errors mean, have you ever programmed before? I suggest you try something more simple if you're stuck on things like this.)

This is a bug with your code - types issue. Replace
OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret);

with

Twitterizer.OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret);

Hope this helps,

Ed :)
 
Share this answer
 
v2
Comments
aryan2010 2-Oct-11 11:59am    
Hello Edward

I have tried your code but I have to use like this then it works properly.
Now I am able to redirect to Twitter. But I am now facing problem of callback.
After login through twitter it does not return to localhost.

Twitterizer.OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret,"oob");


Thanks,
For Your Support
Deepak
Ed Nutting 2-Oct-11 12:36pm    
Of course it won't - how can the Twitter servers redirect to your localhost do you think? The answer is they can't - your site HAS TO BE PUBLICLY HOSTED so that the Twitter servers can actually redirect back to your site! For the Twitter servers, localhost is themselves just as localhost on your machine is your machine. Get yourself a testing server and a domain name and set up your site on that - redirecting will then work. Hope this helps, Ed :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900