简体   繁体   English

将Twitter集成到iPhone应用程序

[英]Integrate twitter to IPhone application

I am hoping to integrate Twitter to my application. 我希望将Twitter集成到我的应用程序中。 My project is created with ARC support. 我的项目是在ARC支持下创建的。 When i added the Twitter framework i also flagged the .m files with -fno-objc-arc . 当我添加Twitter框架时,我还用-fno-objc-arc标记了.m文件。

I could login to twitter (meaning, the authentication process works), and after the authentication that application crashes when i click the tweet button. 我可以登录Twitter(意味着身份验证过程正常),并且在身份验证之后,当我单击tweet按钮时应用程序崩溃。

1.) This is what gets called first, twitter authentication works fine. 1.)这就是所谓的第一个,Twitter身份验证可以正常工作。

-(void)loginTwitterUser{
    if(_engine) return;


    _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];  
    _engine.consumerKey = @"xxxxxx";
    _engine.consumerSecret = @"xxxxxx";

    if (![_engine isAuthorized]) {
        UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
        if (controller) {
            [self presentModalViewController:controller animated:YES];
        }

    }
  • _engine - i have declared this is the .h file, but did not synthesize it in the .m _engine我已经声明这是.h文件,但未在.m文件中进行合成

    1. This is where we are going to tweet 这是我们要发布的地方

       -(void)tweetThis:(id)sender{ [_engine sendUpdate:@"Tweet something"]; } 

3.) other delagate methods 3.)其他脱盐方法

#pragma mark SA_OAuthTwitterEngineDelegate
- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
    NSUserDefaults   *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject: data forKey: @"authData"];
    [defaults synchronize];
}

- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {

    return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"];
}


#pragma mark TwitterEngineDelegate
- (void) requestSucceeded: (NSString *) requestIdentifier {

    NSLog(@"Request %@ succeeded", requestIdentifier);
}

- (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {

    NSLog(@"Request %@ failed with error: %@", requestIdentifier, error);
}

#pragma mark SA_OAuthTwitterController Delegate

In the NSLog username is null . 在NSLog中, username名为null Why is this ? 为什么是这样 ?

- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {

    NSLog(@"Authenticated with user %@", username);

}


- (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller  {

    NSLog(@"Authentication Failure");
}

- (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller {

    NSLog(@"Authentication Canceled");
}

The application crashes in the MGTwitterEngine.m at the return statement. 该应用程序在MGTwitterEngine.m中的return语句中崩溃。

- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
{
    if (!status) {
        return nil;
    }

    NSString *path = [NSString stringWithFormat:@"statuses/update.%@", API_FORMAT];

    NSString *trimmedText = status;
    if ([trimmedText length] > MAX_MESSAGE_LENGTH) {
        trimmedText = [trimmedText substringToIndex:MAX_MESSAGE_LENGTH];
    }

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:trimmedText forKey:@"status"];
    if (updateID > 0) {
        [params setObject:[NSString stringWithFormat:@"%u", updateID] forKey:@"in_reply_to_status_id"];
    }
    NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO];

    return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path 
                        queryParameters:params body:body 
                            requestType:MGTwitterUpdateSendRequest
                           responseType:MGTwitterStatus];
}

How can i resolve this ? 我该如何解决?

Check your SA_OAuthTwitterEngine.m and try to implement the changes below. 检查您的SA_OAuthTwitterEngine.m并尝试实施以下更改。 You should change http to https. 您应该将http更改为https。

- (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://twitter.com/oauth/access_token"];
        self.authorizeURL = [NSURL URLWithString: @"https://twitter.com/oauth/authorize"];
    }
    return self;
}

There's no reason for you to do that, twitter integration has been optimized. 没有理由让您这样做,Twitter集成已得到优化。

Check this link http://www.raywenderlich.com/5519/beginning-twitter-in-ios-5 检查此链接http://www.raywenderlich.com/5519/beginning-twitter-in-ios-5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM