- Home /
Other
Post screenshot photo on facebook
Hi Guys, First I working in android platform with Facebook SDK. All I want is to post the image into facebook timeline, I saw the way how FB.Feed working, it's just taking the url image to post the link. But I have a different method I want to share my photo(screenshot taken inside the application) directly into Facebook with Hastag name like #Contest, #Complaints, #Goal, etc... I searched and they said I have to do this in one way which mean I can save my photo into some link with FB.API and use FB.Feed to call the link. But am confused actually I want to share my screenshot into facebook timeline, I want the way to do it. So far I used this unity scripts to share the image but it's not working.
public void Share()
{
if(!ShareImage)
{
StartCoroutine(ShareImageShot());
}
}
IEnumerator ShareImageShot()
{
ShareImage = true;
yield return new WaitForEndOfFrame();
Texture2D screenTexture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, true);
screenTexture.ReadPixels(new Rect(0f, 0f, Screen.width, Screen.height),0,0);
screenTexture.Apply();
byte[] dataToSave = screenTexture.EncodeToPNG();
string destination = Path.Combine(Application.persistentDataPath, Screenshot_Name);
File.WriteAllBytes(destination, dataToSave);
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", dataToSave, "InteractiveConsole.png");
FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
}
private Texture2D lastResponseTexture;
private string lastResponse = "";
private 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";
}
}
There is no error, but when I press the share button nothing happened. please give me the correct way to do this.
Answer by Umresh · Jul 06, 2015 at 05:31 AM
You have to first login using
FB.Login("public_profile,email,user_friends", LoginCallback);
LoginCallback you can check if successfully logged in or not using FB.IsLoggedIn is true then call FB.API
I did this part and it's working successfully. I really don't know what happening in this condition, when i try debug it's working. But the condition is not working.
I am using facebook sdk version 7.2.2 and it has 2 way to login to facebook. FB.LogInWithReadPermissions and FB.LoginWithRightPermission. which one should I use to share game screenshot on facebook photo. Please help me. Thanks in advance.
Follow this Question
Related Questions
How do I set text after name in Facebook share post? 0 Answers
Facebook share screenshot with link. 1 Answer
How to publish on Facebook from my game? 3 Answers
Capture Screenshot and post to facebook? 0 Answers
Post highscore to Facebook 0 Answers