简体   繁体   中英

Unity3d - 2 issues with Facebook Sharing in Window Phone

Everybody,
I must say that I have post this question 3 times in Unity Community (include answer hub and its forum) but no one can solve it. I use TakeScreenShot() function (it's in the InteractiveConsole example in FB SDK for Unity) to take a screenshot and post it to FB. But there are 2 problems appeared:

How can I fix these problems?

Here is the code of TakeScreenShot() function:

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", "herp derp.  I did a thing!  Did I do this right?");

    FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
    Debug.Log("done");
}

I hope you solved your issues but I will answer anyways to your questions:

•First: the screenshot that's captured is a gray blank.

I think this works for Windows Phone only since very recently on Unity 4.5, update and try again. Unity 4.5 Windows Phone Fixes

Grey Textures happen if you forget to call the Apply method. You will end up with a grey texture if forget to call. I see you are calling tex.Apply() but my guess is that you added it later and you may be seeing an old grey texture. Your code should work as it is. If you still get the grey Texture after updating to version 4.5 or later, try to wait a little time between the Apply and calling the EncodeToPNG(), maybe yield between those calls. Bear in mind that both are expensive operations.

•Second: No one can see my post except me although I set the photo to public.

That is because you have not go live (public) with you facebook app, during development only you will see you and your development team will see the messages. By the way fecebook will not approve hardcoded messages so even though this may work, and I know you based your code on facebook own smaples, you will need to allow the user to edit the message before posting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM