1

我需要在用户的 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];

但是,我如何在这里获取位置参数?任何人都可以帮忙吗?提前致谢。

4

3 回答 3

1

根据本文档,地点对象只能是所需位置的 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 委托获取的,并在上述方法中传递。

接下来,如果此请求成功,则将地点对象插入可变数组中。

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]),现在该应用程序可以成功发布用户当前附近位置的照片。

于 2012-07-18T14:57:56.257 回答
0

FB API 显示 : 'place': 'object 包含与此位置关联的页面的 id 和名称,以及包含地理信息的位置字段,例如纬度、经度、国家和其他字段(字段将根据地理位置和可用性而有所不同)信息)'

1)在iOS 2中启动定位服务)获取当前位置:纬度,经度

使用两个数据经纬度

于 2012-07-15T05:44:42.083 回答
0

Shabib 上面的答案很好(我没有足够的代表直接发表评论),但是您现在还需要指定“字段”参数,以便对 /search 的图形请求成功完成。我的参数字典如下所示:

NSDictionary *params = @{@"type" : @"place",
                        @"center" : centerLocation,
                        @"distance" : @"500",
                        @"fields" : @"id,name"};
于 2016-10-26T14:56:18.727 回答