简体   繁体   中英

Unity3D - Cannot Share Screenshot to Facebook

I am trying to share screenshot image to facebook using unity3D. I am able to login to Facebook through Unity, and after login I am able to access my profile pic.

Now I want to take a screenshot of my app and share it to facebook. I did this using the following code which I took from facebook's developer's page:

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, "Screenshot.png");

    FB.API("me/photos", Facebook.HttpMethod.POST, AuthCallback, wwwForm);
}

But I'm getting the result as "403 Forbidden". What am I doing wrong here? Or is there any other way to share a screenshot to facebook using Unity.

Any help will be appreciated.

Prabha.

Two things to make sure.

1 .Make sure you have publish permission .

2 .If you have publish permission then build the project and run it on a physical Android device. Once you run it, you will then be able to make it post screenshot from the Editor.

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