gpt4 book ai didi

objective-c - Facebook在iOS6.0中使用SLRequest上传照片无论如何都失败了

转载 作者:太空狗 更新时间:2023-10-30 03:34:36 25 4
gpt4 key购买 nike

这是我的 Objc 代码:

ACAccountStore *facebookaccount = [[ACAccountStore alloc] init];
ACAccountType *facebookaccountType = [facebookaccount accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = @{ ACFacebookAppIdKey: @"1234567899876543", ACFacebookPermissionsKey: @[@"publish_stream"], ACFacebookAudienceKey: ACFacebookAudienceFriends };
[facebookaccount requestAccessToAccountsWithType:facebookaccountType options:options completion:^(BOOL granted, NSError *error) {
if(granted) {
NSArray *accountsArray = [facebookaccount accountsWithAccountType:facebookaccountType];
if ([accountsArray count] > 0) {
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];

NSString *sendmessage = @"Face";
NSData *myImageData = UIImagePNGRepresentation(imageSource);

SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://graph.facebook.com/me/photos"] parameters:nil];

[facebookRequest addMultipartData:myImageData withName:@"source" type:@"multipart/form-data" filename:nil];
[facebookRequest addMultipartData:[sendmessage dataUsingEncoding:NSUTF8StringEncoding] withName:@"message" type:@"multipart/form-data" filename:nil];

[facebookRequest setAccount:facebookAccount];

[facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
if (error == nil) {
NSLog(@"responedata:%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}else{
NSLog(@"%@",error.description);
}
}
}
else
{
NSLog(@"error description : %@",[NSString stringWithFormat:@"%@", error.localizedDescription]);
}
}];

最后我得到了这些响应数据:

responedata:{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}

请帮帮我!!!

最佳答案

通过在 addMultipartData 中包含文件名并将消息作为 SLRequest 选项的一部分传递,我可以成功上传照片。

代码:

NSDictionary *parameters = @{@"message": sendmessage};

SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:@"https://graph.facebook.com/me/photos"]
parameters:parameters];

[facebookRequest addMultipartData: myImageData
withName:@"source"
type:@"multipart/form-data"
filename:@"TestImage"];

facebookRequest.account = facebookAccount;

[facebookRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
// Log the result
}];

关于objective-c - Facebook在iOS6.0中使用SLRequest上传照片无论如何都失败了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13236778/

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