简体   繁体   English

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

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

I am trying to get my app (iOS, Android) to allow users to post a screenshot to facebook with a link and a description. 我正在尝试获取我的应用(iOS,Android),以允许用户使用链接和描述将屏幕截图发布到Facebook。 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: 我可以使用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); 

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. 而且我可以使用FB.Feed()从Internet发布带有链接和对用户供稿的描述的图像。 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 https://developers.facebook.com/docs/graph-api/reference/v2.2/photo

After you upload the screenshot using your code above, check the FBResult from your callback method and parse the result with key "id" so you got your uploaded photo id. 使用上面的代码上传屏幕截图后,请从回调方法中检查FBResult并使用键“ id”解析结果,以获取上载的照片ID。

Your photo link will be " https://www.facebook.com/photo.php?fbid=INSERT_YOUR_ID " as the INSERT_YOUR_ID is the id from the result before. 您的照片链接将为“ https://www.facebook.com/photo.php?fbid=INSERT_YOUR_ID ”,因为INSERT_YOUR_ID是之前结果的ID。 Use that link on FB.Feed. 在FB.Feed上使用该链接。

Follow these steps: 跟着这些步骤:

  1. First login using FB.LogInWithPublishPermissions by adding the "publish_actions" permission in parameters. 通过在参数中添加"publish_actions"权限,使用FB.LogInWithPublishPermissions进行首次登录。
  2. Use Facebook Graph API to upload the image. 使用Facebook Graph API上传图片。

For more details link is here . 有关更多详细信息,请单击此处

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

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