Pregunta

I'm using STTwitter to post a message to twitter using the API.

I have two active Twitter profile on my OSX Mavericks in the "Internet Accounts" under systems preferences. One is my personal account, the other is something I'm working on.

I'd like to post a tweet to account #2.

Using STTwitterAPI My code looks like this:

twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];

Now, the rest of the code worked but it's using the wrong account (it's not the first account).

I looked through the code and I thought I could use something like this:

twitter = [STTwitterAPI twitterAPIOSWithAccount:(ACAccount *)];

And get my account from the store. Now, is there a way to get an "ACAccount" by handle (I can't find it anywhere) or is there a way to have a pop-up show to select which account to use? STTwitter didn't show this.

I saw in the API code they are returning the 'index 0' of accounts so I thought about creating a new method

twitter = [STTwitterAPI twitterAPIOSWithHandle:(NSString *)];

but not sure if it's the right way to go.

Any help would be appreciated!

¿Fue útil?

Solución

You can get the accounts defined in System Preferences like this:

ACAccountType *twitterAccountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[_accountStore requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) {

    if(granted == NO) return;

    self.osxAccounts = [_accountStore accountsWithAccountType:twitterAccountType];
}];

Yan can then let the user select the ACAccount instance she wants to use.

See STTwitter OS X demo project for a working example.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top