【问题标题】:how do i publish text and picture to Facebook news feed如何将文本和图片发布到 Facebook 新闻源
【发布时间】:2013-11-26 12:51:19
【问题描述】:

在将 Facebook 整合到 iOS 应用程序方面我还是个新手。我已经阅读了 3 本书,研究了 Facebook 示例,研究了 Facebook 教程,但我不了解 Facebook 集成。我了解如何在 Facebook 上注册应用程序,但我不了解将文本和图片发布到用户新闻提要的代码。我试图了解 Facebook 的教程,但它们都是基于 Xcode 和 iOS 版本的,它们不是最新的。 Facebook 的教程也不一致(例如,登录教程与发布教程的变量不匹配等)。我确实了解如何将文本添加到“initialText”,但在此变量中提供默认文本违反 Facebook 政策。谁能解释如何在 Xcode 中向用户的新闻提要发布文本和图片?

谢谢!

【问题讨论】:

  • 你要使用苹果提供的原生框架吗?
  • 我能做到,是的。我一直在尝试理解 Facebook 的,但我会接受使用苹果的框架。
  • 有人有使用 Facebook 框架的例子吗?

标签: ios facebook facebook-graph-api


【解决方案1】:

你试过这个吗?

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

            SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

            SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
                if (result == SLComposeViewControllerResultCancelled) {

                    NSLog(@"ResultCancelled");

                } else

                {
                    NSLog(@"ResultSuccess");
                }

                [controller dismissViewControllerAnimated:YES completion:Nil];
            };
            controller.completionHandler =myBlock;
            [controller setInitialText:@"Learn iOS6 Social Framework integration"];
            [controller addURL:[NSURL URLWithString:@"http://google.com"]];
            [controller addImage:[UIImage imageNamed:@"myimage.jpeg"]];
            [self presentViewController:controller animated:YES completion:Nil];

        }
        else{

            //NSLog(@"UnAvailable");
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Facebook"
                                                          message:[NSStringstringWithFormat:@"The application cannot post message at the moment. Please login under setting section with your Facebook account."]
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
            [alert show];
            [alert release];
        }

【讨论】:

    【解决方案2】:

    在您的项目中导入社交框架。

    - (void)ShareOnFB    
    {         
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    
        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled) {
    
                NSLog(@"Cancelled");
    
            } else
    
            {
                NSLog(@"Done");
                //Adding the Text to the facebook post value from iOS
    
            }
    
            [controller dismissViewControllerAnimated:YES completion:Nil];
        };
        controller.completionHandler =myBlock;
    
        NSString *fb=[NSString stringWithFormat:@"you can add your text hereand change it as and when needed"];
    
        [controller setInitialText:fb];      
    
    
    
        //Adding the Image to the facebook post value from iOS
    
        [controller addImage:yourImageView.image];
    
    
        [self presentViewController:controller animated:YES completion:Nil];
    
    
    }
    

    【讨论】:

    • 我认为:[控制器 setInitialText:fb]; Facebook 政策不接受吗?
    • 是的,这应该在 fb 上发布图像和文本。您可以动态更改初始文本而不是静态文本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2011-02-16
    • 2011-05-29
    相关资源
    最近更新 更多