我一直在尝试使用FBSDKGraphRequest上传带有标题和标记好友的照片,但我真的很难让标签发挥作用。这就是我得到的:
NSDictionary *parameters = @{
@"caption" : message,
@"picture" : UIImagePNGRepresentation(image),
@"tags" : @[@{@"tag_uid": @902893713061742, @"x":@0.0, @"y":@0.0},
@{@"tag_uid": @902486513129784, @"x":@10.0, @"y":@10.0}],
};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:parameters tokenString:token.tokenString version:@"v2.3" HTTPMethod:@"POST"];
[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(error)
NSLog(@"%@", error);
else
NSLog(@"Success");
}];
[connection start];
但每次我尝试运行它都会抛出此错误:
FBSDKLog:不支持的FBSDKGraphRequest附件:(
{
" tag_uid" = 902893713061742;
x = 0;
y = 0;
},
{
" tag_uid" = 902486513129784;
x = 10;
y = 10;
}
),跳过。
我已经尝试了几种不同的方法来附加@"标签"信息但他们都没有完成这项工作。有谁知道这样做的正确方法?这甚至可能吗? https://developers.facebook.com/docs/graph-api/reference/user/photos/让我这么认为。
编辑:尝试发布没有标签,然后用它们更新帖子ID,但仍然没有成功:(
答案 0 :(得分:3)
您无法使用相同的FBSDKGraphRequest上传带有标题和标记好友的照片。您必须为不同的任务调用不同的方法,如下所示:
对于标题和标签之类的消息:
if ([FBSDKAccessToken currentAccessToken]){
NSDictionary *params = @{
@"message": @"This is a test message",
};
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/feed" parameters:params HTTPMethod:@"POST"]startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (error)
NSLog(@"error:%@", error);
else{
UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"FBSDKGraphRequest" message:@"Text Shared successfully..!" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
[av show];
}
}];
}
发布照片:
if ([FBSDKAccessToken currentAccessToken]){
NSDictionary *params = @{@"sourceImage":UIImagePNGRepresentation(pickedImage)};
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"FBSDKGraphRequest" message:@"Image Shared successfully..!" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
[av show];
} else {
NSLog(@"Graph API Error: %@", [error description]);
}
}];
}
希望能帮到你...... :)。
答案 1 :(得分:1)
您可以上传带有标题的照片,只需将“标题”键更改为“消息”
if FBSDKAccessToken.currentAccessToken().hasGranted("publish_actions") {
let params: [NSObject : AnyObject] = ["message": "Caption", "sourceImage" : UIImagePNGRepresentation(image)]
FBSDKGraphRequest(graphPath: "me/photos", parameters: params, HTTPMethod: "POST").startWithCompletionHandler({ (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
// Handle result
})
}
答案 2 :(得分:0)
以下是帮助您入门的基本代码:
if (![FBSDKAccessToken currentAccessToken]) {
[self alertWithMessage:@"Log into FB and request publish_actions" title:@"Upload Failed"];
return;
}
NSDictionary *params = @{@"source":UIImagePNGRepresentation([UIImage imageNamed:@"snoopy.png"])};
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
[self alertWithMessage:[NSString stringWithFormat:@"Result: %@", result] title:@"Post Photo Success!"];
} else {
NSLog(@"Graph API Error: %@", [error description]);
}
}];
这保证会有效,因为我自己测试了它。请记住检查您拥有的访问令牌是否具有publish_actions权限,因为这可能也会影响您是否可以上传人们的图片。