将Twitter集成到iPhone应用程序 [英] Integrate twitter to IPhone application

查看:129
本文介绍了将Twitter集成到iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将Twitter集成到我的应用程序中.我的项目是在ARC支持下创建的.当我添加Twitter框架时,我还用-fno-objc-arc标记了.m文件.

I am hoping to integrate Twitter to my application. My project is created with ARC support. When i added the Twitter framework i also flagged the .m files with -fno-objc-arc.

我可以登录到twitter(这意味着身份验证过程可以正常工作),并且在身份验证之后,当我单击tweet按钮时,应用程序崩溃了.

I could login to twitter (meaning, the authentication process works), and after the authentication that application crashes when i click the tweet button.

1.)首先,这就是Twitter身份验证的工作原理.

1.) This is what gets called first, twitter authentication works fine.

-(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-我已声明这是.h文件,但未在.m

    • _engine - i have declared this is the .h file, but did not synthesize it in the .m

      1. 这是我们要发布的地方

      1. This is where we are going to tweet

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

    • 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
      

      在NSLog中,usernamenull.为什么会这样?

      In the NSLog username is 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");
      }
      

      应用程序在MGTwitterEngine.m的return语句中崩溃.

      The application crashes in the MGTwitterEngine.m at the return statement.

      - (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];
      }
      

      我该如何解决?

      推荐答案

      检查您的SA_OAuthTwitterEngine.m并尝试实施以下更改.您应该将http更改为https.

      Check your SA_OAuthTwitterEngine.m and try to implement the changes below. You should change http to 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;
      }
      

      这篇关于将Twitter集成到iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆