1- FB.LogInWithReadPermissions
2- FB.LogInWithPublishPermissions
These two function use two type of permissions read and publish from more than 30 permissions provided by Facebook.If we want to share a link and description we can do simply by using FB.ShareLink which open a share dialogue in our app.This dialogue have everything if I'm not wrong except the option to upload stuff from local storage.So what should we do to share screenshot or image from device.It's very simple.we can do this in two steps
- First login using FB.LogInWithPublishPermissions by adding "publish_actions" permission in parameters.
- Use Facebook Graph API to upload image
Her is code snippet to post Screenshot/Image on Facebook
- void Start()
- {
- FB.Init(OnInit);
- }
- private void OnInit()
- {
- LoginToFB();
- }
- public void LoginToFB()
- {
- FB.LogInWithPublishPermissions(new List<string>() { "publish_actions" }, LoginResult);
- }
- private void LoginResult(IResult result)
- {
- //TODO:do what you want
- }
- // Call this function on the sharing event
- public void ShareScreenShot(Texture2D screenShot)
- {
- byte[] encodedScreenShot = screenShot.EncodeToPNG();
- var wwwForm = new WWWForm();
- wwwForm.AddBinaryData("image", encodedScreenShot, "ScreenShot.png");
- wwwForm.AddField("message", "Write description here");
- //calling graph api
- FB.API("me/photos", HttpMethod.POST, ShareScreenShotCallback, wwwForm);
- }
- void ShareScreenShotCallback(IResult result)
- {
- //TODO:do what you want
- }
How to add link / message to this post?
ReplyDeletecheck line 28.... change it a little bit like
DeletewwwForm.AddField("message", "check my game \n" +
"https://play.google.com/store/apps/details?id=com.KayGames.JumpPlus");
using wwwForm.Addfield
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThank you! This helped very much
ReplyDeleteThanks Mudi! I'm glad it's helping
DeleteWhen I use this it automatically posts the screenshot without confirming or showing a popup. Is there a way to fix that?
ReplyDeleteHi Megh, You can create a custom dialogue which contains screenshot,input field for description and a post button.Call "ShareScreenShot" method on post button click.
DeleteHi Khalid Mahmood, I followed your tutorial, but I am getting 403 error in ShareScreenShotCallback. Any idea about that?
ReplyDeleteIt is trying to open the dialog, and show the spin loading for a moment, shows the white box with spin and 'loading', but it closes it and do nothing. In Log it calls the share callback, but don't make actual sharing. :(
ReplyDeleteCan you help me?
Hi, on ShareScreenShotCallback(IResult result), can you please give some examples on how to handle the result, I'm sorry but I'm kind of new on this, and I don't know how to know if everything went ok to say the user that the image was shared or not.
ReplyDeleteThanks in advance.
Hello. How can i do that today? Once the Publish_actions is decrapted.
ReplyDeleteCan you help me please?