Ios Facebook SDK 如何分享图片、link、文字?
Ios Facebook SDK how i can share an image,a link,a text?
我在我的 ios 应用程序中使用最后一个 facebook sdk,我正在尝试分享一张带有描述和 link 的图片。我试过了
[FBDialogs presentShareDialogWithLink]
但是我在共享结果中看不到我的描述文字。我试过了
[FBDialogs presentShareDialogWithPhotoParams]
但是 FBPhotoParams 的描述字段是 "onlyread",我无法添加任何文本。所以我放弃了各种 fbdialogs,我尝试了一些在我的另一个应用程序中工作的东西:
if ([[FBSession activeSession] isOpen]) {
/*
* if the current session has no publish permission we need to reauthorize
*/
if ([[[FBSession activeSession] permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
[self share];
}];
}else{
[self share];
}
}else{
/*
* open a new session with publish permission
*/
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
[self share];
}else{
NSLog(@"error");
}
}];
}
现在这个方法不起作用,return 给我一个错误:
"OAuth \"Facebook Platform\" \"insufficient_scope\" \"(#200) The user hasn't authorized the application to perform this action\"";
我没有分享权限,但用户永远不会看到权限对话框...也许我必须向 Facebook 提交我的申请以获得 "general" ublish_actions 权限脸书应用程式?这只是一个 link,我不想发送构建,等待批准,ecc.. 现在共享带有图像和文本的 link 真的很复杂吗?会有一个更简单的解决方案,我想...我该怎么做?
使用这个,
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithObjectsAndKeys:
name, @"name",
author, @"caption",
linkShare, @"link",
userImage, @"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:parameter
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error)
{
NSLog(@"Error publishing story: %@", error.description);
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
NSLog(@"User cancelled.");
}
else
{
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
NSLog(@"User login");
if (![urlParams valueForKey:@"post_id"])
{
NSLog(@"User cancelled post.");
}
else
{
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
NSLog(@"result %@", result);
}
}
}
}];
- (NSDictionary*)parseURLParams:(NSString *)query
{
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs)
{
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val = [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}
我在我的 ios 应用程序中使用最后一个 facebook sdk,我正在尝试分享一张带有描述和 link 的图片。我试过了
[FBDialogs presentShareDialogWithLink]
但是我在共享结果中看不到我的描述文字。我试过了
[FBDialogs presentShareDialogWithPhotoParams]
但是 FBPhotoParams 的描述字段是 "onlyread",我无法添加任何文本。所以我放弃了各种 fbdialogs,我尝试了一些在我的另一个应用程序中工作的东西:
if ([[FBSession activeSession] isOpen]) {
/*
* if the current session has no publish permission we need to reauthorize
*/
if ([[[FBSession activeSession] permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
[self share];
}];
}else{
[self share];
}
}else{
/*
* open a new session with publish permission
*/
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
[self share];
}else{
NSLog(@"error");
}
}];
}
现在这个方法不起作用,return 给我一个错误:
"OAuth \"Facebook Platform\" \"insufficient_scope\" \"(#200) The user hasn't authorized the application to perform this action\"";
我没有分享权限,但用户永远不会看到权限对话框...也许我必须向 Facebook 提交我的申请以获得 "general" ublish_actions 权限脸书应用程式?这只是一个 link,我不想发送构建,等待批准,ecc.. 现在共享带有图像和文本的 link 真的很复杂吗?会有一个更简单的解决方案,我想...我该怎么做?
使用这个,
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithObjectsAndKeys:
name, @"name",
author, @"caption",
linkShare, @"link",
userImage, @"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:parameter
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error)
{
NSLog(@"Error publishing story: %@", error.description);
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
NSLog(@"User cancelled.");
}
else
{
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
NSLog(@"User login");
if (![urlParams valueForKey:@"post_id"])
{
NSLog(@"User cancelled post.");
}
else
{
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
NSLog(@"result %@", result);
}
}
}
}];
- (NSDictionary*)parseURLParams:(NSString *)query
{
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs)
{
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val = [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}