Arun
Arun

Reputation: 590

iOS - how to get twitter OAuthtoken with username and password

I am new to iPhone and i am just trying to create an app that has a login screen which accept twitter username and password,

But i don't know how to get the Oauthtoken

i got some help to call this url

https://api.twitter.com/oauth/access_token

but don't know what to send the values in these parameters

oauth_consumer_key, oauth_consumer_secret, oauth_nonce, oauth_signature_method.

or any other method to get Oauthtoken from twitter

Thanks, in Advance.

Upvotes: 2

Views: 4011

Answers (2)

nst
nst

Reputation: 3882

1 - Create an application on Twitter web site https://dev.twitter.com/apps you will be given a "consumer key" and a "consumer secret".

2 - Add the STTwitter library into your project https://github.com/nst/STTwitter

3 - The following code will login and print the "access token" and "access token secret" as you requested:

STTwitterAPI *twitter = 
    [STTwitterAPI twitterAPIWithOAuthConsumerName:@"MyApp"
                                      consumerKey:@"BJaKx0V7hdDafkFXK4P08g"
                                   consumerSecret:@"DRSZf2Bc9Qgl0HDE7gGjzXYuQPkwk9gsAYgENFnWJs"
                                         username:@"nst021"
                                         password:@"xxxxxxxx"];

[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {

    NSLog(@"-- access granted for %@", username);
    NSLog(@"-- oauthAccessToken %@", twitter.oauthAccessToken);
    NSLog(@"-- oauthAccessTokenSecret %@", twitter.oauthAccessTokenSecret);
} errorBlock:^(NSError *error) {
    NSLog(@"-- error %@", error);
}];

4 - You can then retrieve the timeline this way:

[twitter getHomeTimelineSinceID:nil count:@"20" successBlock:^(NSArray *statuses) {
    // ...
} errorBlock:^(NSError *error) {
    // ...
}];

Upvotes: 2

AppleDelegate
AppleDelegate

Reputation: 4249

For this you would need a twitter account.Sign in to https://dev.twitter.com/apps to create a new applications and thus you will have oauth_consumer_key, oauth_consumer_secret keys.

Your twitter keys should be similar to these

Consumer key :

Cyn74Fsa8fMn7lvEcnWK8A

Consumer secret :

sUeiThf1tEPV3od9jKBAuN8LdmDsLnAaH5RmG4ZWFE

Upvotes: 1

Related Questions