如何在iOS中将带有图像的位置发布到Facebook? [英] How to post location with image to facebook in IOS?
问题描述
我正在尝试将位置以及图片分享到Facebook.我已成功共享图像,但无法共享位置.下面是我分享图片的代码.
I am trying to share location along with image to facebook. I have successfully shared image but unable to share location. Below is my code of sharing image.
UIImage *facebookImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imagesURL,str]]]];
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"New Happening created on the HappenShare mobile app." forKey:@"message"];
[params setObject:facebookImage forKey:@"picture"];
[FBRequestConnection startWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error)
{
if (error)
{
NSLog(@"error : %@",error);
}
else
{
NSLog(@"Result : %@",result);
}
}];
现在要共享位置,我应该在上面的代码中添加什么参数.我还要附加一个图像,以更好地了解共享位置的样子.下图显示了带有文本的图像如何指示地图中的位置.请为我提出解决方案.
Now for sharing location what parameter should I add in above code. I am attaching an image also to understand better that how the shared location will look like.Below image shows that how the image with text will indicate a location into map. Please suggest me a solution for that.
推荐答案
连同消息",您还需要地方" ID才能作为参数发布.
Along with "message" and you also need "place" ID to post as param.
请求发布动作",以便您可以发布地点/位置.
Request for a "publish_actions" so that you can post a place/location.
以下是我使用的代码:
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:@"Hello World" forKey:@"message"];
[params setObject:@"110503255682430"/*sample place id*/ forKey:@"place"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/feed" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(@"result %@",result);
NSLog(@"error %@",error);
}];
您还可以使用开发者"页面->您的应用->角色中提供的管理员/测试者"帐户进行检查. 使用图资源管理器进行更好的练习: https://developers.facebook.com/tools/explorer/108895529478793?method=POST&path=me%2Ffeed%3F&version=v2.5&message=Hello%20world&place=110503255682430
You can also check this with the "administrator/tester" accounts given in Developer page -> your app -> Roles. Use Graph explorer for better practice: https://developers.facebook.com/tools/explorer/108895529478793?method=POST&path=me%2Ffeed%3F&version=v2.5&message=Hello%20world&place=110503255682430
以下代码可以帮助您获取您所在位置附近的地点ID:
Below code may help you in getting place id near your location:
NSMutableDictionary *params2 = [NSMutableDictionary dictionaryWithCapacity:4L];
[params2 setObject:[NSString stringWithFormat:@"%@,%@",YourLocation latitude,YourLocation longitude] forKey:@"center"]; //Hard code coordinates for test
[params2 setObject:@"place" forKey:@"type"];
[params2 setObject:@"100"/*meters*/ forKey:@"distance"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/search" parameters:params2 HTTPMethod:@"GET"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(@"RESPONSE!!! /search");
}];
OR
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/search?type=place¢er=YourLocationLat,YourLocationLong&distance=500" parameters:nil HTTPMethod:@"GET"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(@"result %@",result);
}];
希望对您有帮助.
这篇关于如何在iOS中将带有图像的位置发布到Facebook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!