Twitter通过Cocoa App使用MGTwitterEngine:HTTP错误401

时间:2012-02-17 11:45:44

标签: macos cocoa twitter mgtwitterengine http-error

我在Cocoa应用程序中使用MGTwitterEngine库来发送推文。

这是我的代码:

    NSString *username = MyName;
    NSString *password = MyPass;

    NSString *consumerKey = ConsumerKey;;
    NSString *consumerSecret = ConsumerSecret;

    // Most API calls require a name and password to be set...
    if (! username || ! password || !consumerKey || !consumerSecret) {
        NSLog(@"You forgot to specify your username/password/key/secret in AppController.m, things might not work!");
        NSLog(@"And if things are mysteriously working without the username/password, it's because NSURLConnection is using a session cookie from another connection.");
    }

    // Create a TwitterEngine and set our login details.
    twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
    [twitterEngine setUsesSecureConnection:NO];
    [twitterEngine setConsumerKey:consumerKey secret:consumerSecret];

    [twitterEngine setUsername:username password:password];

    OAToken *token = [[OAToken alloc] initWithKey:tokenKey
                                  secret:tokenSecret];
    [twitterEngine setAccessToken:token];
    [twitterEngine sendUpdate:@"twitter post"];

它构建没有任何错误。当我运行我的应用程序时,会出现在输出中:

[切换到进程1853线程0x0] Catchpoint 3(投掷) 2012-02-17 17:07:57.790梦想家[1853:1203] MGTwitterEngine:finalURL = http://api.twitter.com/1/statuses/update.xml

2012-02-17 17:07:57.791梦想家[1853:1203] MGTwitterEngine:finalBody = status = twitter%20post

[切换到进程1853线程0x620b] 2012-02-17 18:30:38.491 Dreamer [2067:1203] connectionIdentifier = DAAC2B20-91B6-49A6-90CA-4FD0606DA2FB请求失败,错误=操作无法完成。 (HTTP错误401.)({     body =“\ n \ n只读应用程序无法POST \ n /1/statuses/update.xml \ nnn”;     response =“”; })

Twitter上没有推文。

我在dev.twitter.com上注册了该应用程序,并将访问权限设为Read, Write and Access direct messages

可能出现问题?

1 个答案:

答案 0 :(得分:1)

问题已解决。

如果有人遇到同样的问题,请在更改访问权限后重新生成访问令牌密钥