1

Twitter が API 1.1 に切り替わるまで、MGTwitterEngine + SAOauth を問題なく使用しています。1.1 で動作するように必要な変更を行い、ほとんどすべてが動作します。
ステータスの更新を認証して GET することはできますが、POST はできません。ステータスの更新や友情/作成または破棄を投稿することはできません. 401 エラーが返されます。

エラー ドメイン=HTTP コード=401 「操作を完了できませんでした。(HTTP エラー 401.)

ログインしてステータスを取得できるため、有効なアクセス トークンがあります。POSTできないようです。

4

1 に答える 1

0

SA_OAuthTwitterEngine を使用していると仮定します。メソッド _sendRequestWithMethod... を次の実装に置き換えてみてください。

- (NSString *)_sendRequestWithMethod:(NSString *)method 
                                path:(NSString *)path 
                     queryParameters:(NSDictionary *)params 
                                body:(NSString *)body 
                         requestType:(MGTwitterRequestType)requestType 
                        responseType:(MGTwitterResponseType)responseType
{

    BOOL isPOST = (method && [method isEqualToString:@"POST"]);

    NSString *fullPath = path;

    if (params) {
        fullPath = [self _queryStringWithBase:fullPath parameters:(isPOST ? nil : params) prefixed:YES];
    }

    // --------------------------------------------------------------------------------
    // modificaiton from the base clase
    // the base class appends parameters here
    // --------------------------------------------------------------------------------
    //    if (params) {
    //        fullPath = [self _queryStringWithBase:fullPath parameters:params prefixed:YES];
    //    }
    // --------------------------------------------------------------------------------

    NSString *urlString = [NSString stringWithFormat:@"%@://%@/%@", 
                           (_secureConnection) ? @"https" : @"http",
                           _APIDomain, fullPath];
    NSURL *finalURL = [NSURL URLWithString:urlString];
    if (!finalURL) {
        return nil;
    }

    // --------------------------------------------------------------------------------
    // modificaiton from the base clase
    // the base class creates a regular url request
    // we're going to create an oauth url request
    // --------------------------------------------------------------------------------
    //    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:finalURL 
    //                                                              cachePolicy:NSURLRequestReloadIgnoringCacheData 
    //                                                          timeoutInterval:URL_REQUEST_TIMEOUT];
    // --------------------------------------------------------------------------------

    OAMutableURLRequest *theRequest = [[[OAMutableURLRequest alloc] initWithURL:finalURL
                                                                       consumer:self.consumer 
                                                                          token:_accessToken 
                                                                          realm: nil
                                                              signatureProvider:nil] autorelease];
    if (method) {
        [theRequest setHTTPMethod:method];
    }
    [theRequest setHTTPShouldHandleCookies:NO];

    // Set headers for client information, for tracking purposes at Twitter.
    [theRequest setValue:_clientName    forHTTPHeaderField:@"X-Twitter-Client"];
    [theRequest setValue:_clientVersion forHTTPHeaderField:@"X-Twitter-Client-Version"];
    [theRequest setValue:_clientURL     forHTTPHeaderField:@"X-Twitter-Client-URL"];

    NSMutableArray *oauthParams = [NSMutableArray array];

    for (id key in params) {
        id value = [params objectForKey:key];
        [oauthParams addObject:[OARequestParameter requestParameterWithName:key value:value]];
    }

    [theRequest setParameters:oauthParams];

    // --------------------------------------------------------------------------------
    // modificaiton from the base clase
    // our version "prepares" the oauth url request
    // --------------------------------------------------------------------------------
    [theRequest prepare];

    // Create a connection using this request, with the default timeout and caching policy, 
    // and appropriate Twitter request and response types for parsing and error reporting.
    MGTwitterHTTPURLConnection *connection;
    connection = [[MGTwitterHTTPURLConnection alloc] initWithRequest:theRequest 
                                                            delegate:self 
                                                         requestType:requestType 
                                                        responseType:responseType];

    if (!connection) {
        return nil;
    } else {
        [_connections setObject:connection forKey:[connection identifier]];
        [connection release];
    }

    return [connection identifier];
}
于 2013-06-16T11:13:33.220 に答える