2

I have read the docs and many forum posts regarding this, but I just cannot retrieve the username of the authorised user while using Sharekit. I am using oAuth.

The user can authenticate ok, and I can post status updates to Twitter. The docs for Sharekit say this about retrieving the username:

Accessing Stored Logins

If your web service uses basic auth, you'll likely need to send the username and password along with the shared item. After a user has been authenticated, the credentials are stored and easily accessible.

// To retrieve a stored value:
// self = your service class
// In this example, let's retrieve the username and password:
NSString *username = [self getAuthValueForKey:@"username"];
NSString *password = [self getAuthValueForKey:@"password"];

//The keys used to retrieve the data are the same keys you used 
// when defining your login form:
- (NSArray *)authorizationFormFields
{
    return [NSArray arrayWithObjects:
            [SHKFormFieldSettings label:@"Username"
                                          key:@"username" <---
                                          type:SHKFormFieldTypeText
                                          start:nil],
            [SHKFormFieldSettings label:@"Password"
                                          key:@"password" <---
                                          type:SHKFormFieldTypePassword
                                          start:nil],           
            nil];
}

I have tried using

NSString *username  = [SHK getAuthValueForKey:@"username"];

and

NSString *username  = [SHKTwitter getAuthValueForKey:@"username"];

but neither return the username.

Has anyone managed to retrieve this information? Any help is much appreciated.

Peetz
  • 167
  • 1
  • 14

3 Answers3

1

As you said twitter is not using basic auth.. it is using oauth. Your app never gets the username or the password from the authentication, it only gets the oauth tokens... so the username is not stored in the login database.

If you want the username you have to query it using the appropriate api calls.

You could check the sendStatus function of the twitter module of shareKit and create a function that get's https://dev.twitter.com/docs/api/1/get/account/verify_credentials ... there you get the user's name and other stuff

Bastian
  • 10,403
  • 1
  • 31
  • 40
  • Thanks for the reply. I thought Sharekit allowed us to grab the username somehow from when the authentication takes place using the code I posted above? Not sure how this works though. – Peetz Aug 09 '11 at 14:50
  • Thanks. I got the twitter username along with other credentials using this api – Priyanka V Feb 03 '12 at 11:14
0

Twitter OAuth does return the username, but it's not automatically saved by ShareKit. To find it yourself, go to:

- (void)tokenAccessTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data 

in SHKOAuthSharer.m and retrieve and save the username, or any other data you need from the responseDictionary object. For example, the username can be fetched by [responseDictionary objectForKey:@"screen_name"]. Then, save it to the NSUserDefaults or any other object you can retrieve later.Of course this will happen only on the next time the user logs in to Twitter using ShareKit. Cheers!

Almog C
  • 795
  • 6
  • 14
0

This problem is solved in reborn ShareKit. See FAQ.

Vilém Kurz
  • 3,401
  • 2
  • 34
  • 43