因此,我正在创建一个 iPhone 应用程序,当用户使用 Facebook Graph API 签入某个位置时,该应用程序需要能够上传照片。
现在我的代码是这样的:
if (![delegate.facebook isSessionValid])
[delegate.facebook authorize:[NSArray arrayWithObjects:@"publish_stream", @"offline_access", @"publish_checkins", nil]];
parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:[placeDictionary objectForKey:@"id"] , @"place",
serialisedCoordinates, @"coordinates",
message, @"message",
pickedImage, @"picture",
@"Via the official REDACTED app", @"application", nil];
[delegate.facebook requestWithGraphPath:@"me/checkins" andParams:parameters andHttpMethod:@"POST" andDelegate:fbCheckInResultHandler];
其中“pickedImage”是从 UIImagePickerController 返回的 UIImage。
即使我选择了一张图片(即,pickedImage != nil),签入时也不会上传任何图片。签入显示在 Facebook 上,带有消息、坐标和应用程序信息,只是没有图像。
真的希望有人能帮忙。
干杯,基兰
这是进行签入时调用的整个函数:
-(void)fbPostCheckInWithMessage:(NSString *)message andFriends:(NSArray *)friends {
if (![delegate.facebook isSessionValid]) {
NSLog(@"Session invalid");
[delegate.facebook authorize:[NSArray arrayWithObjects:@"publish_stream", @"offline_access", @"publish_checkins", nil]];
} else {
NSLog(@"Session valid");
}
NSMutableString *friendsIDString;
friendsIDString = [NSMutableString stringWithFormat:@"%@", [[friends objectAtIndex:0] userID]];
if ([friends count] > 1) {
for (User *f in taggedFriends) {
if (f != [taggedFriends objectAtIndex:0]) {
[friendsIDString appendString:[NSString stringWithFormat:@", %@", f.userID]];
}
}
}
NSLog(@"Tagged Friends: %@", friendsIDString);
SBJSON *jsonWriter = [SBJSON new];
NSMutableDictionary *locationDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%f", userLocation.coordinate.latitude], @"latitude",
[NSString stringWithFormat:@"%f", userLocation.coordinate.longitude], @"longitude", nil];
NSString *serialisedCoordinates = [jsonWriter stringWithObject:locationDictionary];
NSData *pictureData = UIImagePNGRepresentation(pickedImage);
NSLog(@"picture: %@", pictureData);
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:[placeDictionary objectForKey:@"id"] , @"place",
serialisedCoordinates, @"coordinates",
pictureData, @"message",
pickedImage, @"picture",
@"Via the official REDACTED app", @"application", nil];
[delegate.facebook requestWithGraphPath:@"me/checkins" andParams:parameters andHttpMethod:@"POST" andDelegate:fbCheckInResultHandler];
}
我正在使用friendsIDString 来获取用户的朋友的ID。我已从此处的示例中删除了此功能,因为它已全部被注释掉,因为我试图找出导致问题的原因(即照片标记)。只是想澄清一下。
--UPDATE-- 这是我设置pickImage的方式。我使用 UIImagePickerController 中的委托方法:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
NSLog(@"Picked image");
pickedImage = [[UIImage alloc] init];
pickedImage = image;
[imagePickerController dismissModalViewControllerAnimated:YES];
}