0

テーブルビューでユーザーのタイムラインを使用して開発中のアプリがあります。すべてのアプリで同じユーザーのタイムラインになります。私はすでにこれをコーディングしており、完全に機能します。私の問題は、呼び出しで API バージョンを 1 から 1.1 に変更すると、機能しなくなることです。すべてのツイートはツイート シートを通過するため、認証は必要ありません。呼び出しで API バージョンを変更するだけでなく、新しい API でタイムラインを表示するためだけに承認を設定する以外に、コードを追加する必要がありますか? 単純に 1 人のユーザーのタイムラインを表示し、ツイート シートを使用して応答する以外の機能は追加していません。コードを添付しました。どんな助けでも素晴らしいでしょう。ありがとうございました。

- (void)fetchTweets
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://api.twitter.com/1/statuses/user_timeline.json?include_rts=false&screen_name=johnnelm9r&count=100"]];

        if (data == nil)
        {

        }

        else
        {
            NSError *error;

            tweets = [NSJSONSerialization JSONObjectWithData:data
                                                     options:kNilOptions
                                                       error:&error];
        }

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.twitterTableView reloadData];
        });

    });

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];
    self.reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
    [self.reachability startNotifier];
}
4

1 に答える 1

0

これが私が思いついたものです。それは私がそれをするのに必要なことをうまく呼びます。うまくいけば、それは他の誰かにも役立つでしょう。

- (void)fetchTweets
{
twitterLoader.animationImages = [NSArray arrayWithObjects:
                                 [UIImage imageNamed:@"StatusIndicator.png"],
                                 [UIImage imageNamed:@"StatusIndicator1.png"],
                                 [UIImage imageNamed:@"StatusIndicator2.png"],
                                 [UIImage imageNamed:@"StatusIndicator3.png"],
                                 [UIImage imageNamed:@"StatusIndicator4.png"],
                                 [UIImage imageNamed:@"StatusIndicator5.png"],
                                 [UIImage imageNamed:@"StatusIndicator6.png"],
                                 [UIImage imageNamed:@"StatusIndicator7.png"],
                                 [UIImage imageNamed:@"StatusIndicator8.png"],
                                 [UIImage imageNamed:@"StatusIndicator9.png"],
                                 [UIImage imageNamed:@"StatusIndicator10.png"],
                                 [UIImage imageNamed:@"StatusIndicator9.png"],
                                 [UIImage imageNamed:@"StatusIndicator8.png"],
                                 [UIImage imageNamed:@"StatusIndicator7.png"],
                                 [UIImage imageNamed:@"StatusIndicator6.png"],
                                 [UIImage imageNamed:@"StatusIndicator5.png"],
                                 [UIImage imageNamed:@"StatusIndicator4.png"],
                                 [UIImage imageNamed:@"StatusIndicator3.png"],
                                 [UIImage imageNamed:@"StatusIndicator2.png"],
                                 [UIImage imageNamed:@"StatusIndicator1.png"],
                                 nil];

twitterLoader.animationDuration = 0.8;
[twitterLoader startAnimating];

ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType =
[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    //  Request permission from the user to access the available Twitter accounts
[store requestAccessToAccountsWithType:twitterAccountType
                               options:nil
                            completion:^(BOOL granted, NSError *error)
 {
 if (!granted)
     {
     NSLog(@"User rejected access to the account.");
     }

 else
     {
     [twitterLoader startAnimating];

     NSArray *twitterAccounts =
     [store accountsWithAccountType:twitterAccountType];

     if ([twitterAccounts count] > 0)
         {
         ACAccount *account = [twitterAccounts objectAtIndex:0];
         [twitterLoader startAnimating];

         NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
         [params setObject:@"johnnelm9r" forKey:@"screen_name"];
         [params setObject:@"100" forKey:@"count"];
         [params setObject:@"0" forKey:@"include_entities"];
         [params setObject:@"0" forKey:@"include_rts"];

             //  The endpoint that we wish to call
         NSURL *url =
         [NSURL
          URLWithString:@"http://api.twitter.com/1.1/statuses/user_timeline.json"];

         SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                                 requestMethod:SLRequestMethodGET
                                                           URL:url
                                                    parameters:params];


             // Attach the account object to this request
         [request setAccount:account];

         [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
          {
          if (!responseData)
              {
              NSLog(@"%@", error);
              }

          else
              {
              NSError *jsonError;
              tweets = [NSJSONSerialization JSONObjectWithData:responseData
                                                       options:NSJSONReadingMutableLeaves
                                                         error:&jsonError];
              if (tweets)
                  {
                  NSLog(@"%@", tweets);
                  [self.twitterTableView reloadData];

                  [twitterLoader stopAnimating];
                  }

              else
                  {
                  NSLog(@"%@", jsonError);
                  }
              }
          }];
         [self.twitterTableView reloadData];
         [twitterLoader stopAnimating];
         }
     }
 }];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(reachabilityChanged:)
                                             name:kReachabilityChangedNotification
                                           object:nil];
self.reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
[self.reachability startNotifier];
}

また、簡単なローダーと到達可能性を追加しました。不要な場合は、下部にあるNSNotificationを削除してください。

そして、必ず追加してください

アカウントとソーシャルフレームワーク

ヘッダーファイルを、それを使用する.mファイルにインポートします。

幸運を!

于 2013-01-02T05:50:46.657 に答える