繁体   English   中英

Facebook Unity API-发布带有链接和描述的屏幕截图吗?

[英]Facebook Unity API - post screenshot with link and description?

我正在尝试获取我的应用(iOS,Android),以允许用户使用链接和描述将屏幕截图发布到Facebook。 我可以使用FB.API()将屏幕快照从我的应用程序上传到Facebook为我的应用程序自动生成的用户相册,方法是:

    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()从Internet发布带有链接和对用户供稿的描述的图像。 有没有一种方法可以将屏幕快照通过链接和说明发布到用户的提要中?

    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);

您可以参考此处以获取更多可用字段的详细信息

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

使用上面的代码上传屏幕截图后,请从回调方法中检查FBResult并使用键“ id”解析结果,以获取上载的照片ID。

您的照片链接将为“ https://www.facebook.com/photo.php?fbid=INSERT_YOUR_ID ”,因为INSERT_YOUR_ID是之前结果的ID。 在FB.Feed上使用该链接。

跟着这些步骤:

  1. 通过在参数中添加"publish_actions"权限,使用FB.LogInWithPublishPermissions进行首次登录。
  2. 使用Facebook Graph API上传图片。

有关更多详细信息,请单击此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM