2

I created a Game on Unity3D and I am in the process of adding support for Facebook. What I would like to achieve is the users posting a screenshot of the game showing the score. I succeeded technically, but Facebook rejected my game because the text message that is posted along with the picture is pre-filled, and that violates section 2.3 of their Platform Policy.

Here is a pice of code found on the Example that comes with Facebook SDK for Unity in which I based mine... I guess this sample code created by Facebook does not comply either.

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

So before investing a lot of time implementing a text editor in Unity3D for the sole purpose of posting to Facebook, I am looking for advise.

First, is there a way I can get my app approved without creating a text editor at all?

1) If I just post the screenshot will Facebook approve my game? Or I still will get rejected for posting a pre-filled image?

2) Is there a way to achieve this without creating an App on Facebook and requesting approval for "publish_actions" permission? maybe passing the image to the Facebook App?

If there is no option and I must create a text editor with a touch keyboard to allow the user to edit the message, what would be the best way to do it keeping compatibility for iOS, Android and Windows Phone 8.

Baltico
  • 483
  • 3
  • 9

1 Answers1

0

I did manage to get approved by Facebook, but believe me, there is no shortcut. You need to offer a way for the user to preview what is being posted, and edit the text before submitting it.

In the end it was not that hard, thanks to the GUI controls. You can use GUI.DrawTexture to show a preview of the screen captured. You can use GUI.TextField to allow the user to edit the message and use GUI.Button to show "Share" and "Cancel" buttons. Put all this code on the OnGUI() method.

You can even add the profile picture next to the TextBox so the user gets the social feeling and also so the user knows which user is posting. During my tests I noticed the App cache the Facebook tokens and even if you change the Facebook user on the phone and Facebook App, my game kept using the original user when posting.

Since the question focus on how to edit the Text and not on how to interact with Facebook I will post the GUI code here, but not the facebook code which is similar to what I previously posted. The code assumes you have all the textures mentioned and that the user already agreed to give permissions for: "public_profile,publish_actions".

The code also uses a Boolean named socialAskMessage that you need to set true in order to show the user interface. Also when you set socialAskMessage it is advisable that you ignore all other user input. In my game I reactivate all user input after 0.5 seconds in another function named DelayedCanClick(). The method to actually post to facebook resides inside social.PublishOnFacebook() that I do not present here.

void OnGUI() {
//GUI.Label(new Rect(10, 10, 100, 20), "Res" + Screen.width + " x " + Screen.height);
if (socialAskMessage)
{
    //Background
    GUI.DrawTexture(new Rect(0f, 0f, Screen.width, Screen.height / 3f),socialBackground,ScaleMode.StretchToFill);
    //Screenshot
    GUI.DrawTexture(new Rect(margin, margin, Screen.width/3f - margin*2f, Screen.height / 3f - margin*2f),screenshot,ScaleMode.ScaleToFit);
    //Profile Picture
    if (profilePicture != null)
        GUI.DrawTexture(new Rect(Screen.width*7f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f), profilePicture);

    //Hanlde Enter/Return event/Share Button
    if (GUI.Button(new Rect(Screen.width*8f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f),shareButtonTexture,emptyGUIStyle)
        ||
        ( (Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) ) 
        )
    {
        audioTac.Play();
        if (socialMessage.StartsWith("Write"))
            socialMessage = "";
        else if (socialMessage.Length > 0)
        {
            socialAskMessage = false;
            social.PublishOnFacebook();
        }
        else //If empty
            socialMessage = "Write a comment...";

    }

    //Hanlde ESC/Cancel Button
    if (GUI.Button(new Rect(Screen.width*9f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f),cancelButtonTexture,emptyGUIStyle)
        ||
        ( (Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape) ) 
        )
    {
        audioTac.Play();
        socialAskMessage = false;
    }

    if (socialAskMessage) //If still needed, show it
    {
        GUI.skin.textField.fontSize = 22;
        GUI.skin.textField.fontStyle = FontStyle.Bold;
        GUI.skin.textField.wordWrap = true;
        GUI.skin.textField.focused.textColor = Color.white;
        GUI.SetNextControlName("socialTextArea");
        socialMessage = GUI.TextField(new Rect(Screen.width/3f, margin, Screen.width/2.75f - margin*2f, Screen.height / 3f - margin*2f), socialMessage, 200);
        GUI.FocusControl("socialTextArea");
        if ((socialMessage.Length == 17 || socialMessage.Length == 19) && socialMessage.StartsWith("Write a comment"))
            socialMessage = socialMessage.Replace("Write a comment","").Replace(".","");
    }
    else //Dont show it anymore, reactivate click
    {
        StartCoroutine(DelayedCanClick());
    }
}
}
Baltico
  • 483
  • 3
  • 9