Facebook Unity API - 带有链接和描述的截图? [英] Facebook Unity API - post screenshot with link and description?

查看:523
本文介绍了Facebook Unity API - 带有链接和描述的截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的应用程序(iOS,Android)允许用户通过链接和描述向Facebook发布屏幕截图。我可以使用FB.API()将我的应用程序的截图从Facebook自动生成的用户专辑上传到我的应用程序,方法如下:

I am trying to get my app (iOS, Android) to allow users to post a screenshot to facebook with a link and a description. I am able to use FB.API() to upload screenshots from my app to a user's album that Facebook autogenerated for my app, via:

    int width = Screen.width;
    int height = Screen.height;
    Texture2D 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();

    string picName = "Idioman_" + Time.time + ".png";
    wwwForm.AddBinaryData("image", screenshot, picName);

    Debug.Log("trying to post screenshot");
    FB.API("me/photos", Facebook.HttpMethod.POST, PostPicCallback, wwwForm); 

我可以使用FB.Feed()通过链接发布来自互联网的图像以及对用户Feed的描述。有没有办法通过链接和描述将屏幕截图发布到用户的Feed?

And I am able to use FB.Feed() to post an image from the internet with a link and a description to a user's feed. Is there a way to post the screenshot to a user's feed with a link and a description?

推荐答案

    var snap = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
    snap.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    snap.Apply();
    var screenshot = snap.EncodeToPNG();

    int i = UnityEngine.Random.Range (0, 2);

    var wwwForm = new WWWForm();
    wwwForm.AddBinaryData("image", screenshot, "picture.png");
    wwwForm.AddField ("name", "this will be the caption for the image");

    FB.API("me/photos", HttpMethod.POST, CallbackUploadImage, wwwForm);

您可以在这里参考可用字段的更多详细信息

you can refer here for more details of the available fields

https://developers.facebook.com/ docs / graph-api / reference / v2.2 / photo

这篇关于Facebook Unity API - 带有链接和描述的截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆