![](/img/trans.png)
[英]SLRequest - Twitter returns code 215 (Bad authentication data)
[英]Updating Twitter profile picture with iOS SLRequest results in error 215 bad authentication data
我正在嘗試根據Twitter文檔的https://dev.twitter.com/rest/reference/post/account/update_profile_image發布新的個人資料圖片,這是我的代碼:
NSData *jpeg = UIImageJPEGRepresentation(img, 0.9);
NSString *base64 = [jpeg base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/account/update_profile_image.json"];
NSDictionary *params = @{@"image" : base64
};
SLRequest *request =
[SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:url
parameters:params];
[request setAccount:self.twitterAccount];
[request performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse,
NSError *error) {
...
}
但是URL響應是:
errors = (
{
code = 215;
message = "Bad Authentication data.";
}
);
我究竟做錯了什么? 我的ACAccount
是有效的(我剛剛嘗試在Settings.app中從Twitter登出並登錄)。
您的代碼看起來不錯,但是您肯定缺少一些東西。
確保:
requestAccessToAccountsWithType
方法)。 授予權限后,您應該在“允許這些應用程序使用您的帳戶”下的Twitter設置(在“設置”應用程序中)中看到您的應用程序。 SLRequest
的Twitter帳戶有效,並且不是nil
。 在上述條件下,我現在能夠成功修改我的個人資料圖片。 以下是基於您提供的代碼的示例代碼:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
ACAccount *twitterAccount = [accounts lastObject];
NSData *jpeg = UIImageJPEGRepresentation([UIImage imageNamed:@"photo.jpg"], 0.9);
NSString *base64 = [jpeg base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/account/update_profile_image.json"]
parameters:@{@"image" : base64}];
[request setAccount:twitterAccount];
[request performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse,
NSError *error)
{
NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil]);
}];
}
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.