【问题标题】:Facebook SDK FB.API post screenshot with user's messageFacebook SDK FB.API 发布截图和用户消息
【发布时间】:2016-05-08 16:19:09
【问题描述】:

我正在尝试发布屏幕截图并将其上传到用户的 Facebook 帐户。我正在使用 unity (c#) 并使用 facebook SDK,它与我从他们的文档中获得的示例代码一起工作正常。

我什至设法“预先填写”了一条消息并将其与屏幕截图一起发布。但是预填消息是违反Facebook Platform Policyexanples的,所以我正在寻找一种方法来使用相同的方法,让用户在不违反Facebook平台政策的情况下填写消息。

这是我使用的工作代码:

     private IEnumerator TakeScreenshot()
     {
         yield return new WaitForEndOfFrame();

         var width = Screen.width;
         var height = Screen.height;
         var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
         // Read screen contents into the texture
         tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
         tex.Apply();
         byte[] screenshot = tex.EncodeToPNG();

         var wwwForm = new WWWForm();
         wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
         wwwForm.AddField("message","some message"); // violating Facebook Platform Policy
         FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
     }

【问题讨论】:

    标签: android facebook facebook-graph-api unity3d


    【解决方案1】:

    这就是InputFieldButton 组件发挥作用的地方。使用InputField 获取用户消息并在单击按钮时发送。您可以在截屏前隐藏InputField 和发送Button

    public InputField userInput;
    public Button postButton;
    
    
    public void OnEnable()
    {
        postButton.onClick.AddListener(postToFB);
    }
    
    void postToFB()
    {
        Debug.Log("Posting To FB");
        StartCoroutine(TakeScreenshot(userInput.text));
    }
    
    private IEnumerator TakeScreenshot(string textToPost)
    {
        //Hide User Input
        userInput.gameObject.SetActive(false);
    
        //Hide Send Button
        postButton.gameObject.SetActive(false);
    
        yield return new WaitForEndOfFrame();
    
        var width = Screen.width;
        var height = Screen.height;
        var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
        // Read screen contents into the texture
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();
        byte[] screenshot = tex.EncodeToPNG();
    
        var wwwForm = new WWWForm();
        wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
        wwwForm.AddField("message", textToPost);
        FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
    }
    
    public void OnDisable()
    {
        postButton.onClick.RemoveAllListeners();
    }
    

    【讨论】:

    • 我记得我在某处读到,facebook 的平台政策也不允许自定义输入。不过现在找不到了
    • @Sag1v 你在说什么?您不应该重新填写输入。您让用户输入他们想要的任何内容。这就是上面的代码所做的,并且没有 facebook 政策说它不好。假设您修改了userInput.text 而不是使用用户输入的内容,那么这是不行的。
    • @Sag1v "您可以使用我们的分享对话框在帖子中预填充单个主题标签,但不要预填充任何非通过 API 创建的内容" 文本必须由用户不是你。观看此youtube.com/watch?v=tGz48L0m5nc 我的答案中的代码是可以的。你问题中的那个不是。预填充是指您在发布之前或之后修改用户输入的内容。
    • 我不是说你使用了预填充,但我记得我们不能使用自定义输入而不是 facebook 的对话框...试图找到它
    • 好吧,我找不到它,但我认为您在这里是关于制作我们自己的 Share-UI 的能力。正如我在这里看到的:developers.facebook.com/docs/games/services/sharing(基于 API 的共享)。无论如何感谢您的建议
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多