如何从iOS App中的Twitter获取用户信息?

时间:2014-03-17 12:26:24

标签: ios objective-c twitter

我正在使用 MGTwitterEngine ,但不幸的是我收到了401或403错误。

在以下方法中,我尝试了

- (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate {
    if (self = (id) [super initWithDelegate: delegate]) {
        self.requestTokenURL = [NSURL URLWithString: @"https://twitter.com/oauth/request_token"];
        self.accessTokenURL = [NSURL URLWithString: @"http://twitter.com/oauth/access_token"];
        self.authorizeURL = [NSURL URLWithString: @"http://twitter.com/oauth/authorize"];
    }
    return self;
}


- (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate {
    if (self = (id) [super initWithDelegate: delegate]) {
        self.requestTokenURL = [NSURL URLWithString: @"https://api.twitter.com/oauth/request_token"];
        self.accessTokenURL = [NSURL URLWithString: @"https://api.twitter.com/oauth/access_token"];
        self.authorizeURL = [NSURL URLWithString: @"https://api.twitter.com/oauth/authorize"];
    }
    return self;
}


- (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate {
    if (self = (id) [super initWithDelegate: delegate]) {
        self.requestTokenURL = [NSURL URLWithString: @"https://twitter.com/oauth/request_token"];
        self.accessTokenURL = [NSURL URLWithString: @"https://api.twitter.com/oauth/access_token"];
        self.authorizeURL = [NSURL URLWithString: @"https://twitter.com/oauth/authorize"];
    }
    return self;
}

但我在这里没有成功。

 AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication]delegate];
            // Twitter Initialization / Login Code Goes Here
            if(!app._engine)
            {
                NSLog(@"Init the Object ");

                app._engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
                app._engine.consumerKey    = kOAuthConsumerKey;
                app._engine.consumerSecret = kOAuthConsumerSecret;
            }

            if(![app._engine isAuthorized])
            {
                NSLog(@"IN if of isAuthorized ");

                UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:app._engine delegate:self];


                if (controller)
                {
                    [self presentViewController:controller animated:YES completion:nil];

                }
            }

还有其他更好,更简单的图书馆来获取Twitter的用户信息吗?

1 个答案:

答案 0 :(得分:0)

Twitter API已更新至api.twitter.com/1

另外,让我们确保所有链接都是安全的。示例:

self.accessTokenURL = [NSURL URLWithString: @"https://twitter.com/oauth/access_token"];

self.authorizeURL = [NSURL URLWithString: @"https://twitter.com/oauth/authorize"];