我需要在用户的 Facebook 墙上发布一张带有用户位置的照片(从相机拍摄)。
现在,facebook 照片对象有一个名为 place 的字段。 :
object containing id and name of Page associated with this location, and a location field containing geographic information such as latitude, longitude, country, and other fields (fields will vary based on geography and availability of information)
现在我如何获得这个地方,将它与照片一起附加并上传到用户墙。
这是我的照片上传代码:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
resultImage, @"picture",
location, @"place",
nil];
[appDelegate.facebook requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
但是,我如何在这里获取位置参数?任何人都可以帮忙吗?提前致谢。
最佳答案
根据 this documentation,地点对象只能是所需位置的 Facebook 页面 ID。 .因此,这就是我在上传照片时设法获取用户位置的方法。
-(void)fbCheckForPlace:(CLLocation *)location
{
NSString *centerLocation = [[NSString alloc] initWithFormat:@"%f,%f",
location.coordinate.latitude,
location.coordinate.longitude];
NSLog(@"center location is : %@",centerLocation);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"place", @"type",
centerLocation, @"center",
@"1000", @"distance",
nil];
[centerLocation release];
[appDelegate.facebook requestWithGraphPath:@"search" andParams:params andDelegate:self];
}
当前位置是通过调用 CLLocation Manager 委托(delegate)获取的,并在上述方法中传递。
接下来,如果此请求成功,则将地点对象插入可变数组中。
NSArray *resultData = [result objectForKey:@"data"];
for (NSUInteger i=0; i<[resultData count] && i < 5; i++)
{
[self.listOfPlaces addObject:[resultData objectAtIndex:i]];
}
然后触发照片上传方法:
- (void)uploadPhotoWithLocation
{
NSString *placeId = [[self.listOfPlaces objectAtIndex:0] objectForKey:@"id"];
params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.resultImage, @"picture",
placeId, @"place",
nil];
[appDelegate.facebook requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
}
我已经占据了可用签到的第一个附近位置(
[self.listOfPlaces objectAtIndex:0]
),现在该应用程序可以成功发布用户当前附近位置的照片。
关于ios - 通过带有用户位置的 iOS Graph API 将照片上传到自己的墙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11483157/