【问题标题】:Photo Upload to own wall via iOS Graph API with user's location通过带有用户位置的 iOS Graph API 将照片上传到自己的墙
【发布时间】:2012-07-14 01:15:09
【问题描述】:

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

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

【问题讨论】:

    标签: ios facebook-graph-api photo-upload


    【解决方案1】:

    地点对象只能是根据this documentation 的所需位置的Facebook Page 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委托获取,并传入上述方法。

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

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

    【讨论】:

      【解决方案2】:

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

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

      使用两个数据经纬度

      【讨论】:

        【解决方案3】:

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

        NSDictionary *params = @{@"type" : @"place",
                                @"center" : centerLocation,
                                @"distance" : @"500",
                                @"fields" : @"id,name"};
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-05-30
          • 2012-08-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-17
          相关资源
          最近更新 更多