Hi,
I have a twitter application and I want to check the following
scenario.
A user logged into his twitter account and already granted permissions
to make status notes through another application.
When user hits the connect button, the navigation directs to Allow/
Deny page which he already confirmed. I want this to by pass and
automatically allowed the user to update the status notes in their
twitter wall.
I used the following code and it doesn't work as expected. Could you
please help me to solve this?
const string requestUrl = http://twitter.com/oauth/request_token;;
// This is the URL to exchange the request token for an
access token
const string accessUrl = http://twitter.com/oauth/
access_token;
// This is the URL to access a protected resource; in this
case,
// the authorized user’s timeline
const string userTimeline = http://twitter.com/statuses/
user_timeline.xml;
// This is your application’s consumer key
const string key = key;
// This is your application’s consumer secret
const string secret = secret;
// This is the URL to send a user for authorization
const string authorizeUrl = http://twitter.com/oauth/
authorize?oauth_token=;
// Retrieve and parse the request token
var response = OAuth.GetRequestToken(requestUrl, key,
secret);
var collection = HttpUtility.ParseQueryString(response);
var requestToken = new { Token = collection[0],
TokenSecret = collection[1] };
// At this point, your application must wait for the user
to return
var url = String.Concat(authorizeUrl,
Uri.EscapeDataString(requestToken.Token));
string value = OAuth.GetAccessToken(accessUrl,
key,
secret,
access token of a
user,// this is a unique value for a user
access token secret of
the user); // unique value for a user
// above method doesn't give me the the required value in fact, it
gives an error calledthis method needs to call with request
tokens
I want the following 4 lines of code to be executed only if the
user hasn't granted permissions or not logged in
Process proc = new Process();
proc.StartInfo.FileName = iexplore;
proc.StartInfo.Arguments = url;
proc.Start();
// Exchange the request token for the access token after
user approval
response = OAuth.GetAccessToken(accessUrl,
key,
secret,
requestToken.Token,
requestToken.TokenSecret);
while (String.IsNullOrEmpty(response.Trim()))
{
response = OAuth.GetAccessToken(accessUrl,
key,
secret,
requestToken.Token,
requestToken.TokenSecret);
}
if (response.Contains(screen_name))
{
collection = HttpUtility.ParseQueryString(response);
var accessToken = new { Token = collection[0],
TokenSecret = collection[1] };
// Get the user timeline using OAuth credentials
response = OAuth.GetProtectedResource(userTimeline,
GET,
key,
secret,
accessToken.Token,
accessToken.TokenSecret);
OAuthTokens accToken = new OAuthTokens();
accToken.AccessToken = collection[0].ToString();
accToken.AccessTokenSecret = collection[1].ToString();
accToken.ConsumerKey = key;
accToken.ConsumerSecret = secret;
TwitterStatus TweetStatus = new
TwitterStatus(accToken);
TweetStatus.Update(test message);
}