2

我在我的 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 (throw) 2012-02-17 17:07:57.790 Dreamer[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\n\n"; response = ""; })

Twitter 上也没有任何推文。

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

问题可能出在哪里?

4

1 回答 1

1

问题解决了。

如果有人会遇到同样的问题,那么在访问更改后重新生成您的访问令牌密钥

于 2012-02-17T15:32:35.393 回答