问题
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];
But, how do I get the location parameter here? Can anyone help? Thanks in advance.
回答1:
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];
}
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];
}
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.
回答2:
the FB API shows : '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)'
1)start location service in iOS 2)got current location: latitude, longitude
use the two data latitude, longitude
回答3:
The answer above by Shabib is great (I don't have enough rep to comment directly), but you now need to also specify the "fields" parameter in order for the graph request to /search to complete successfully. My parameters dictionary looks like this:
NSDictionary *params = @{@"type" : @"place",
@"center" : centerLocation,
@"distance" : @"500",
@"fields" : @"id,name"};
来源:https://stackoverflow.com/questions/11483157/photo-upload-to-own-wall-via-ios-graph-api-with-users-location