由于 twitter api 已更改,我的应用程序不再发布推文。之前每件事都运行良好,并且根据新的 API,只有请求模式应该改变?所有其他初始化引擎和休息的东西应该是一样的吗?
并且应该修改共享的方法,所以我修改了它,但得到“Bad Authentication 215”。我从 twitter 本身生成的身份验证标头中获得的所有令牌信息和其他内容:
- (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);
}