我需要在用户的 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];
}
当前位置是通过调用CLLocationManager 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/