简体   繁体   English

Facebook SDK FB.API发布带有用户消息的屏幕截图

[英]Facebook SDK FB.API post screenshot with user's message

I'm trying to post a screenshot and upload it to the user's facebook account. 我正在尝试发布屏幕截图并将其上传到用户的Facebook帐户。 I'm working with unity (c#) and using facebook SDK and it's working fine with the example code i got from their Docs. 我正在使用unity(c#)并使用facebook SDK,并且我从他们的文档中获得的示例代码可以正常工作。

I even managed to "pre-fill" a message and post it with the screenshot. 我什至设法“预填充”一条消息,并将其与屏幕截图一起发布。 But pre-filling a message is against Facebook Platform Policy exanples , so i'm looking for a way to use the same method and let the user fill in a message while i don't break Facebook Platform Policy. 但是,预先填写消息与Facebook Platform Policy 极端做法不符 ,因此,我在寻找一种使用相同方法的方法,并在我不违反Facebook Platform Policy的情况下让用户填写消息。

here is the working code i used: 这是我使用的工作代码:

     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);
     }

This is where InputField and Button components comes into play. 这是InputFieldButton组件起作用的地方。 Get user message with InputField and send when Button is clicked. 使用InputField获取用户消息,并在单击Button时发送。 You can hide both the InputField and send Button before taking screenshot. 您可以在截屏之前隐藏InputField和send 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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Facebook JS-FB.api()仅发布消息,不发布媒体附件 - Facebook JS - FB.api() only posts message, not media attachment Facebook FB.api Noationation停止工作 - Facebook FB.api Notication stopped working Unity Facebook API FB.API()java.io.FileNotFoundException - Unity facebook API FB.API() java.io.FileNotFoundException 从android fb sdk发布消息到Facebook墙总是错误 - Post message to facebook wall from android fb sdk always error Unity Facebook SDK:将屏幕快照发布到墙上不起作用 - Unity Facebook SDK: post screenshot to wall not working 如何使用FB Android API将LibGDX屏幕截图分享到Facebook? - How to share LibGDX screenshot to Facebook using FB Android API? Android:使用FB SDK 4.x以编程方式发布到facebook - Android: post to facebook programatically with FB SDK 4.x facebookconnectplugin cordova fb.api不返回任何数据 - facebookconnectplugin cordova fb.api not returning any data 如何使用fb android sdk从默认帐户而非用户自己的帐户中获取来自Facebook相册的图像? - How to get image from facebook album using fb android sdk from a default account not the user's own account? 如何使用Android Facebook SDK在朋友的墙上张贴一些消息? - How do I post some message on a friend's wall using the Android Facebook SDK?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM