通过带有用户位置的iOS Graph API将照片上传到自己的墙上 [英] Photo Upload to own wall via iOS Graph API with user's location

查看:47
本文介绍了通过带有用户位置的iOS Graph API将照片上传到自己的墙上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在用户的Facebook墙上张贴一张带有用户位置的照片(从相机拍摄).现在,facebook照片对象具有一个名为地点"的字段:

I need to post a photo (taken form the camera) in the users facebook wall with the location of the user. Now, the facebook photo object has a field named 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)

现在如何获得该地点,将其与照片附在一起,然后将其上传到用户墙上.这是我的照片上传代码:

Now how do I get the place, attach it with the photo and upload it in the users wall. This is my code for photo upload:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       resultImage, @"picture",
                                       location, @"place",
                                       nil];

        [appDelegate.facebook requestWithGraphPath:@"me/photos"
                                         andParams:params
                                     andHttpMethod:@"POST"
                                       andDelegate:self];

但是,如何在这里获取location参数?有人可以帮忙吗?预先感谢.

But, how do I get the location parameter here? Can anyone help? Thanks in advance.

推荐答案

根据

The place object can only be a Facebook Page Id of the desired location according to this documentation. So, here is how I managed to get user's location while uploading photo.

-(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委托获得的,并通过上述方法传递.

the current location is obtained by calling CLLocation Manager delegate and passed in the above method.

接下来,如果此请求成功,则将放置对象插入可变数组中.

Next, if this request is successful, the place objects are inserted in a mutable array.

NSArray *resultData = [result objectForKey:@"data"];
        for (NSUInteger i=0; i<[resultData count] && i < 5; i++) 
        {
            [self.listOfPlaces addObject:[resultData objectAtIndex:i]];
        }

然后触发照片上传方法:

And then the photo uploading method is fired:

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

I have taken the first nearby place of the available check-ins ([self.listOfPlaces objectAtIndex:0]) and now the app can successfully post photos with the users current nearby location.

这篇关于通过带有用户位置的iOS Graph API将照片上传到自己的墙上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆