无法使用 SLComposeViewController 将图像发布到 Facebook?
Posted
技术标签:
【中文标题】无法使用 SLComposeViewController 将图像发布到 Facebook?【英文标题】:Unable to post image into facebook using SLComposeViewController? 【发布时间】:2013-02-14 05:49:24 【问题描述】:我想将图片发布到 facebook 和 twitter。我对 twitter 很好,但对使用 SLComposeViewController 类的 facebook 不满意。没有添加图像,我可以将文本和 url 发布到 facebook。问题是当我使用添加图像时,我无法发布此图像以及文本、网址。 SLComposeViewController 在我发送时显示图像、文本和 url。我有正确的 appId,我没有收到任何错误。但问题仍然存在。我不知道问题出在哪里。请帮帮我。
- (void)performFBRequestUploadForImage
[self showListOfFaceBookAccountsFromStore];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result)
NSString *output;
switch (result)
case SLComposeViewControllerResultCancelled:
output = @"ACtionCancelled";
break;
case SLComposeViewControllerResultDone:
output = @"Post Successfull";
[self dismissViewControllerAnimated:YES completion:nil];
break;
default:
break;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Face Book Message" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
;
[mySLComposerSheet addImage:[UIImage imageNamed:@"images4.jpg"]];
[mySLComposerSheet setInitialText:@"I am developer."];
[mySLComposerSheet addURL:[NSURL URLWithString:@"http://***.com/"]];
[mySLComposerSheet setCompletionHandler:completionHandler];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
- (void)showListOfFaceBookAccountsFromStore
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
if( [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] )
NSDictionary *options = @
@"ACFacebookAppIdKey" : myAppId,
@"ACFacebookPermissionsKey" : @[@"publish_stream"],
@"ACFacebookAudienceKey" : ACFacebookAudienceFriends;
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error)
if(granted)
ACAccount * account = [[accountStore accountsWithAccountType:accountType] lastObject];
NSLog(@"Facebook user: %@",[account username]);
if([account username]==NULL)
[self facebookAlert];
else
else
NSLog(@"Read permission error: %@", [error localizedDescription]);
];
else
[self facebookAlert];
【问题讨论】:
【参考方案1】:我在我的项目中使用了下面的代码来发布它工作正常的图像。
if([SLComposeViewController instanceMethodForSelector:@selector(isAvailableForServiceType)] != nil)
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
if (result == SLComposeViewControllerResultCancelled)
NSLog(@"Cancelled");
else
NSLog(@"Done");
[controller dismissViewControllerAnimated:YES completion:Nil];
;
controller.completionHandler =myBlock;
[controller setInitialText:@"Check out my Christmas Gift!"];
[controller addImage:@"gift.jpg"];
[self presentViewController:controller animated:YES completion:Nil];
您只需尝试按照以下教程进行操作
-
Tutorial 1
2.Tutorial 2
【讨论】:
感谢重播。我已经添加了你的代码,但我没有得到图像。但是当我删除 addImage: 方法时,我的脸书上收到了消息。 你只需检查图片是否存储在facebook相册而不是墙上 @PrasadG 我加了两个教程看看吧 感谢您的建议。你是对的。这些照片在相册中。 这段代码没有解决我的问题。检查***.com/questions/20881429/…【参考方案2】:我查看了互联网,发现最近 1 或 2 天有一些与此问题相关的讨论,它们似乎与 Facebook 错误有关。因此,如果您的代码成功将消息和图像发布到 Twitter,请不要担心!你做得对。
https://***.com/questions/14868518/sharekit-not-sharing-link-to-facebook/
https://discussions.apple.com/thread/4805777
【讨论】:
【参考方案3】: I have resolved through open present-view controller in navigation-bar.it may help you.
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:shareFrom];
[controller addImage:self.photoImageView.image];
[controller addURL:[NSURL URLWithString:dayCareWebsite]];
dispatch_async(dispatch_get_main_queue(), ^
[self.navigationController presentViewController:controller animated:YES completion:nil];
);
【讨论】:
以上是关于无法使用 SLComposeViewController 将图像发布到 Facebook?的主要内容,如果未能解决你的问题,请参考以下文章
无法使用 StorageClass 配置卷 - 无法获取存储帐户的存储密钥
Worklight Studio 和本地开发,有时无法使用 Java 类,有时无法使用 HTML 文件