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