iOS 用のアプリを開発しているため、ユーザーの認証時に作成されたオブジェクトをインスタンス化して使用できるようにする方法を知る必要があります。
gtm-oauth2 フレームワークを適切に実装する OAuth2 メソッドを使用しています。ユーザー エントリは、Web ビューに表示されたログイン フォームを確認し、正しく認証されます。その瞬間、ドキュメントで詳しく説明されているように、私は次のようになります。
if (error != nil){
    // Do whatever to control the error
}
else
{
    // Authentication succeeded
    // Assign the access token to the instance property for later use
    self.accessToken = myAuth.accessToken;
    [myAuth setShouldAuthorizeAllRequests:YES];
    [self setAuth:myAuth];
    // Display the access token to the user
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Authorization Succeeded"
                                                        message:[NSString stringWithFormat:@"Access Token: %@", myAuth.accessToken]
                                                       delegate:self
                                              cancelButtonTitle:@"Dismiss"
                                              otherButtonTitles:nil];
    [alertView show];
}
その後、同じコントローラーで、ユーザーが認証されたら、次のように self.auth オブジェクトを使用して API にアクセスします。
[request setURL:getCartsURL];
[request setValue:self.accessToken forHTTPHeaderField:@"Authorization"];
[self.auth authorizeRequest:request
          completionHandler:^(NSError *error) {
              NSString *output = nil;
              if (error) {
                  output = [error description];
              } else {
                  // Synchronous fetches like this are a really bad idea in Cocoa applications
                  //
                  // For a very easy async alternative, we could use GTMHTTPFetcher
                  NSURLResponse *response = nil;
                  NSData *data = [NSURLConnection sendSynchronousRequest:request
                                                       returningResponse:&response
                                                                   error:&error];
                  if (data) {
                      // API fetch succeeded
                      output = [[NSString alloc] initWithData:data
                                                     encoding:NSUTF8StringEncoding];
                      SBJsonParser *jsonParser = [SBJsonParser new];
                      // Parse the JSON into an Object
                      id parsed = [jsonParser objectWithString:output];
                      NSArray *arrayResponse = [[NSArray alloc] initWithArray:parsed];
                  } else {
                      // fetch failed
                      output = [error description];
                  }
              }
          }];
これまで、オブジェクトのローカル インスタンスを使用してきましたself.authが、アプリ全体の任意のポイントからそのオブジェクトにグローバルにアクセスしたい場合、これでは不十分です。init ビュー コントローラーには問題ありませんが、アプリ全体には問題ありません。
この最初のView Controllerにアクセスして、いつでもオブジェクトを取得できると思います。しかし、グローバルにインスタンス化して、アプリのどこからでもアクセスできるようにするためのより良い方法があると思います。
これで私を助けてもらえますか?
どうもありがとう。