0

I'm trying to add a feature to allow users to log-in via Facebook/Twitter/Google+ and leave comments in my app. I also want to display the avatars of other users that have left comments.

If the users has previously signed-in with Twitter, I can use TWRequest to call the API using [request setAccount:self.account], but if not, the request returns "Bad Authentication data".

I created an application on Twitter, how I use the consumer key and consumer secret with TWRequest or are those used just for OAuth with a user?

4

2 回答 2

2

在STTwitter的帮助下使用仅应用程序身份验证解决了我的问题。

apiWrapper = [STTwitterAPIWrapper
              twitterAPIApplicationOnlyWithConsumerKey:@"..."
              consumerSecret:@"..."];


[apiWrapper verifyCredentialsWithSuccessBlock:^(NSString *token) {
    DDLogInfo(@"Twitter App logged in with token: %@",token);
} errorBlock:^(NSError *error) {
    DDLogCError(@"Twitter verify credentials error %@",error);
}];
于 2013-07-15T07:26:24.510 回答
2

考虑使用反向身份验证。.

反向认证最常见的用例。允许用户使用他们的 OS X 或 iOS Twitter 帐户注册/登录远程服务。

iOS/OSX     Twitter     Server
|------------>|             |   reverse auth.
|< - - - - - -|             |   access tokens
|             |             | 
|-------------------------->|   access tokens
|             |
|             |<------------|   access Twitter on user's behalf
|             | - - - - - ->|

以下是使用STTwitter进行反向身份验证的方法:

STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerName:nil
                                                          consumerKey:@"CONSUMER_KEY"
                                                       consumerSecret:@"CONSUMER_SECRET"];

[twitter postReverseOAuthTokenRequest:^(NSString *authenticationHeader) {

    STTwitterAPI *twitterAPIOS = [STTwitterAPI twitterAPIOSWithFirstAccount];

    [twitterAPIOS verifyCredentialsWithSuccessBlock:^(NSString *username) {

        [twitterAPIOS postReverseAuthAccessTokenWithAuthenticationHeader:authenticationHeader
                                                            successBlock:^(NSString *oAuthToken,
                                                                           NSString *oAuthTokenSecret,
                                                                           NSString *userID,
                                                                           NSString *screenName) {

                                                                // use the tokens...

                                                            } errorBlock:^(NSError *error) {
                                                                // ...
                                                            }];

    } errorBlock:^(NSError *error) {
        // ...
    }];

} errorBlock:^(NSError *error) {
    // ...
}];
于 2013-08-18T05:58:57.010 回答