简体   繁体   中英

Sharing screenshot with text to facebook unity

I'm trying to give the user the possibility to post a screenshot of his game on facebook with the dowload link of the game.

I've looked a bit and it seemed it would be possible with FB.API, but I can't manage to make it work. Aparently you need a permission but I can't to find which permission and how to give it.

I'm using unity 2020.3.21f1

Here is what I'm doing for now

public void ShareScreenShot(Texture2D screenShot)
{
    byte[] encodedScreenShot = screenShot.EncodeToPNG();

    var wwwForm = new WWWForm();
    wwwForm.AddBinaryData("image", encodedScreenShot, "ScreenShot.png");
    wwwForm.AddField("message", "Venez me défier : https://randomlink.blablabla");

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

void ShareScreenShotCallback(IResult result)
{
    if (result.Error != null)
    {
        Debug.Log(result.Error);
    }
    else
    {
        Debug.Log("sharing success");
    }
}

If anyone of you knows how it can be done, it would be of great help, thanks

I suppose you need to login to facebook with custom permissions, because the default one only allows you to send invitations to choosen friends.

https://developers.facebook.com/docs/unity/reference/current/FB.LogInWithPublishPermissions/

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