gpt4 book ai didi

iphone - 如何使用 iOS 5 Twitter 框架发送直接消息?

转载 作者:行者123 更新时间:2023-12-03 18:35:46 26 4
gpt4 key购买 nike

我正在尝试使用 this代码,和 these instructions直接发消息。发布普通推文效果非常好,但是当我尝试发送直接消息时,我收到了 406。

这是完整的代码:

ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

// Request access from the user to access their Twitter account
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
// Did user allow us access?
if (granted == YES)
{
// Populate array with all available Twitter accounts
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];

// Sanity check
if ([arrayOfAccounts count] > 0)
{
// Keep it simple, use the first account available
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

// Build a twitter request
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/direct_messages/new.format"];
NSDictionary *p = [NSDictionary dictionaryWithObjectsAndKeys:
@"UserName", @"screen_name",
@"Super awsome direct message", @"text",
nil
];

TWRequest *postRequest = [[TWRequest alloc]
initWithURL: url
parameters: p
requestMethod: TWRequestMethodPOST
];

// Post the request
[postRequest setAccount:acct];

// Block handler to manage the response
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
CCLOG(@"Response Data\n%@", responseData);
if (!error)
CCLOG(@"%@", [error description]);
}];
}
}
}];

最佳答案

关于iphone - 如何使用 iOS 5 Twitter 框架发送直接消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10253709/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com