gpt4 book ai didi

iphone - 在 iOS 中使用新的 api (1.1) 发布推文

转载 作者:行者123 更新时间:2023-11-28 19:09:21 25 4
gpt4 key购买 nike

由于更改了 twitter api,我的应用程序不再发布推文。之前一切正常,根据新的 API,只有请求模式应该改变吗?初始化引擎和其余的所有其他内容应该相同吗?

而且共享的方法应该修改,所以我修改了它但得到“Bad Authentication 215”。我从 Twitter 本身生成的身份验证 header 中获得的所有 token 信息和其他信息:

- (void) shareOnTwitter
{
NSString *urlString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/update.json"];

NSURL *url = [NSURL URLWithString:urlString];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

[request setHTTPMethod:@"POST"];

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

[dict setValue:@"check Check CHECK" forKey:@"status"];

[dict setValue:@"-- - - - - -" forKey:@"oauth_consumer_key"];

[dict setValue:@"- - - - - - -" forKey:@"oauth_nonce"];

[dict setValue:@"- - - - - - -" forKey:@"oauth_signature"];

[dict setValue:@"HMAC-SHA1" forKey:@"oauth_signature_method"];

[dict setValue:@"- - - - - - -" forKey:@"oauth_timestamp"];

[dict setValue:@"- - - - - - -" forKey:@"oauth_token"];

[dict setValue:@"1.0" forKey:@"oauth_version"];

NSString *jsonString = [dict JSONRepresentation];

NSData *jsonData = [NSData dataWithBytes:[jsonString UTF8String] length:jsonString.length];

[request setHTTPBody:jsonData];

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

NSLog(@"My request...%@", jsonString);

NSData *urlData;

NSURLResponse *response1;

NSError *error = nil;

urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response1 error:&error];

if(error)
{
NSLog(@"Error %@",error);
}

if(!urlData)
{
NSLog(@"No connection!");
}

NSString *responseStr = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

NSLog(@" Twitter : ... %@", responseStr);
}

最佳答案

试试下面的代码。它对我有用:

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
if (accounts.count)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:@"check Check CHECK" forKey:@"status"];

NSString *retweetString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/update.json"];
NSURL *retweetURL = [NSURL URLWithString:retweetString];
TWRequest *request = [[TWRequest alloc] initWithURL:retweetURL parameters:dict requestMethod:TWRequestMethodPOST];
request.account = [accounts objectAtIndex:0];

[request performRequestWithHandler:^(NSData *responseData1, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (responseData1)
{
NSError *error1 = nil;
id response = [NSJSONSerialization JSONObjectWithData:responseData1 options:NSJSONReadingMutableLeaves error:&error1];
}
}];
}
}

}];

关于iphone - 在 iOS 中使用新的 api (1.1) 发布推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17206014/

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