我正在将Twitter集成到我的应用程序中。我用Google搜索和搜索堆栈,找不到正确的步骤。
谁能告诉我它如何详细工作。
谢谢。

最佳答案

我希望这能帮到您 。 。 。

1.将以下课程添加到您的项目中
GTMOAuthAuthentication.h / m
GTMOAuthSignIn.h / m
GTMHTTPFetcher.h / m
GTMOAuthViewControllerTouch.h / m
GTMOAuthViewTouch.xib

2。添加以下框架
Security.framework和SystemConfiguration.framework。

3 .set -ObjC构建选项,用于应用程序目标的“其他链接器标志”。

4。然后是时候进行一些编码了。

import GTMOAuthAuthentication.h and GTMOAuthViewControllerTouch.h

    - (void)signInWithTwitter
    {
    NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/request_token"];
    NSURL *accessURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];
    NSURL *authorizeURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/authorize"];
    NSString *scope = @"http://api.twitter.com/";

    GTMOAuthAuthentication *auth = [self authForTwitter];

    [auth setCallback:@"http://www.noop.com/OAuthCallback"];

    GTMOAuthViewControllerTouch *viewController;

    viewController = [[GTMOAuthViewControllerTouch alloc] initWithScope:scope
                                                                 language:nil
                                                          requestTokenURL:requestURL
                                                        authorizeTokenURL:authorizeURL
                                                           accessTokenURL:accessURL
                                                           authentication:auth
                                                           appServiceName:@"AppName : Twitter"
                                                                 delegate:self
    finishedSelector:@selector(viewController:finishedWithAuth:error:)];

    [appDelegate.navigationController pushViewController:viewController animated:YES];
    }

    - (GTMOAuthAuthentication *)authForTwitter {
    GTMOAuthAuthentication *auth = [[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
                consumerKey:TWITTER_CONSUMER_KEY
                 privateKey:TWITTER_CONSUMER_SECRET];

    [auth setServiceProvider:@"Twitter"];

    return auth;
    }

    - (void)viewController:(GTMOAuthViewControllerTouch *)viewController finishedWithAuth:(GTMOAuthAuthentication *)auth error:(NSError *)error {

        if(error)
        {
             //handle error
        }
        else
        {
            // do stuff as per your app.
        }
    }

NOte : if you get error message like "failed to validate oauth signature and token" then check you system time is correct or not .

09-07 11:43