- Home /
Problem when take a screenshot and share to Facebook
Edited: I build this game for Android and Window Phone platfomr.
Hello guys, In my game, when player die, there is a stat board appear with a "Share" button, what I want is when player hit the button, it capture game's screenshot and then share to Facebook. For easily understand, It work exactly like the "Share" button in Flappy Bird game.
Here is my code, I tested with a Debug.log("done") at the end of the TakeScreenshot() function and when I hit the button, I got the result: there is a word "done" in console window, the game is stopped just a bit of second (I think it's has captured the screenshot) but nothing appeared.
if (// share button)
callFB();
void callFB () {
if (!FB.IsLoggedIn) {
FB.Login("email,publish_actions", LoginCallback);
}
else StartCoroutine(TakeScreenshot());
}
void LoginCallback(FBResult result) {
FbDebug.Log("LoginCallback");
if (FB.IsLoggedIn) {
OnLoggedIn();
}
}
void OnLoggedIn() {
FbDebug.Log("Logged in. ID: " + FB.UserId);
}
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");
}
private Texture2D lastResponseTexture;
private string lastResponse = "";
public string ApiQuery = "";
void Callback(FBResult result)
{
lastResponseTexture = null;
if (result.Error != null)
lastResponse = "Error Response:\n" + result.Error;
else if (!ApiQuery.Contains("/picture"))
lastResponse = "Success Response:\n" + result.Text;
else
{
lastResponseTexture = result.Texture;
lastResponse = "Success Response:\n";
}
}
Answer by Kamuiyshirou · May 03, 2014 at 04:16 PM
@BraveVN, your question is important. Who can help!
Hi $$anonymous$$amuiyshirou, If you update your FB SD$$anonymous$$ and Unity to latest version (FB is 5.0.3 and Unity is 4.3.4 or more), you can use the TakeScreenshot() function in InteractiveConsole example. I've tested and it worked perfectly in Unity Editor. But there're some problems: First, the screenshot that you shared cannot seen by anyone except you although it's set to public. Second, I'm making a game for Window Phone and when I build to export it, a tons of errors appeared but in Android is not.
Your answer
Follow this Question
Related Questions
Facebook share screenshot with link. 1 Answer
facebook sdk share screen shot 0 Answers
Can't Post Screenshot To Facebook Wall 1 Answer
Share Screenshot Image to Facebook with Facebook SDK 0 Answers
Facebook app review for screenshot share 0 Answers