Facebook Screenshot Share Android

Does anyone know of any good plug-ins (preferably not too expensive) that will allow me to screenshot and share to Facebook for android? Or if unity has a script that would be great :slight_smile:

First you’ll need the Facebook SDK: https://developers.facebook.com/docs/unity/downloads

Code to get Screenshot and post would be something like

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

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

When I put the code in I get a an error on the Callback on this line:

FB.API(“me/photos”, Facebook.HttpMethod.POST, Callback, wwwForm);

same here, the documentation from facebook SDK are really poor for beginners…

What does the error say?

Same problem here… The photo is correctly uploaded but the ID is not returned on the callback.

There is no error but the response.Text seems to be invalid JSON.

// The printed length is 74
Debug.Log( "Result length = " + result.Text.Length.ToString() );

// Deserialize JSON
object response = Json.Deserialize( result.Text );

// Get data
var resultData = ( Dictionary< string, object > )( ( ( Dictionary< string, object> )response )[ “data” ] );
foreach( KeyValuePair< string, object > kvp in resultData )
{
// Never called
Debug.Log( string.Format( “key = {0} :: data = {1}”, kvp.Key, kvp.Value ) );
}

// Try to get photo ID which should be there according to documentation but its not
object id;
if ( resultData.TryGetValue( “id”, out id ) )
{
// Do something
}

I got an issue when taking a screenshot using FB.API(). FB team deny my request publish_actions permission by
“Your app’s users must enter all content in the user message field. Don’t auto-populate the message field with any content, including links and hashtags, even if you allow users to edit the content before sharing. Watch this informational video for more information, and seePlatform Policy 2.3”

How can my app allow user explicit writing their status via sharing dialog as well as embedding a screenshot?