在React Native中使用GraphRequest将mp4发布到Facebook [英] Posting mp4 to Facebook using GraphRequest in React Native

查看:137
本文介绍了在React Native中使用GraphRequest将mp4发布到Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用react-native-fbsdk中的GraphRequest从我的应用发布到FB.具体来说,我正在尝试发布指向外部托管的mp4视频的链接,因此该链接的网址为https://img.myapp.com/image_id.mp4之类.这是我的请求的代码:

I am using GraphRequest from react-native-fbsdk to post to FB from my app. Specifically, I am trying to post a link to an mp4 video that is hosted externally, so at a url like https://img.myapp.com/image_id.mp4. Here is the code for my request:

return new Promise(function(resolve, reject) {
  const post = new GraphRequest('/me/feed', {
    httpMethod: 'GET',
    version: 'v2.9',
    ...payload,
  }, (err, result) => {
    if (err) {
      reject(err);
    }
    resolve();
  });

  new GraphRequestManager().addRequest(post).start();
});

这是payload:

  {
    httpMethod: 'POST',
    parameters: {
      type: { string: 'article' },
      message: { string: message || '' },
      caption: { string: 'Powered by MyApp' },
      link: { string: media.url },
      ref: { string: uuid },
      picture: { string: media.url },
      source: { string: media.url },
      properties: [
        { name: { string: 'type' }, text: { string: 'video.other' } },
      ], 
  }

我的核心问题是我想将mp4链接发布到FB并查看视频循环(因为它只有几秒钟长).我很确定此properties属性是我应该在其中指定类型,高度,宽度和其他属性的地方,我将在其他位置添加一个元标记以在链接中传递有关视频的信息.然而, 用properties编写的方式得到此错误:graph api Error: Unexpected value for parameter 'properties'. Request parameters need to be objects with a 'string' field.

My core issue is that I want to post an mp4 link to FB and see the video loop (as it is only a few seconds long). I am pretty sure that this properties property is where I should be specifying type, height, width, and other properties that I would add a meta tag for elsewhere to pass along info about the video in the link. However, with properties written the way I have it I get this error: graph api Error: Unexpected value for parameter 'properties'. Request parameters need to be objects with a 'string' field.

这是Graph API中properties块的屏幕截图-POST docs( https://developers.facebook.com/docs/graph-api/reference/v2.11/post ):

Here is a screen shot of the properties block in the Graph API - POST docs (https://developers.facebook.com/docs/graph-api/reference/v2.11/post):

我已经尝试过为此对象(或数组?)尝试许多不同的配置,并且它们都返回此错误.是否有人熟悉使用GraphRequest发布mp4视频,或者至少可以为我提供有关如何使用properties参数的建议?预先感谢!

I have tried as many different configurations for this object (or array?) as I can think of and they all return this error. Is there anyone out there that is familiar with posting an mp4 video using GraphRequest or can at least advise me on how to use the properties parameter? Thanks in advance!

推荐答案

要使MP4以可在线播放的视频形式显示(对于已启用该功能的用户,可以在新闻Feed中自动播放),您需要上传视频,然后再发布.

For the MP4 to show up as an inline-playable video (and, for those that have enabled it, auto-play in the news feed) you need to upload the video prior to posting it.

由于您提到从外部链接进行发布,因此只要您至少定位Graph API的2.3版,就可以将URL发送到视频文件,而不必上传原始数据.需要注意的一个限制是,您提供的URL上的视频需要在5分钟内由Facebook的抓取器下载.如果您的视频较大或服务器速度较慢,最好使用分块上传过程.

Since you mentioned posting from an external link, as long as you are targeting at least version 2.3 of the Graph API you can just send the URL to the video file rather than uploading the raw data. One limitation to be aware of is that the video at the URL you provide needs to be downloadable by Facebook's scraper within 5 minutes. If you have a large video or a slow server, better to use the chunked upload process.

以下是有关视频上传过程的更多信息: https://developers .facebook.com/docs/graph-api/video-uploads

Here's some more information on the video upload process: https://developers.facebook.com/docs/graph-api/video-uploads

要开始使用,请确保使用/videos端点而不是/feed:

To start you off, make sure to use the /videos endpoint rather than /feed:

new GraphRequest('/me/videos'

您将使用的参数与/feed终结点有些不同,可以在这里引用: https://developers.facebook.com/docs/graph-api/reference/video#Creating

The parameters you'll use are a bit different than the /feed endpoint and can be referenced here: https://developers.facebook.com/docs/graph-api/reference/video#Creating

您将要专门查看将URL发送到视频文件的file_url参数,如果希望将视频自动发布到用户的新闻源,则将使用is_explicit_share参数.您可以使用description代替message,您提供的文本将显示在墙上的墙上.将所有内容与原始代码放在一起:

You'll want to look specifically at the file_url parameter where you'll be sending the URL to your video file, and the is_explicit_share parameter if you want the video to be posted to the user's News Feed automatically. You can use description instead of message and the text you provide will show up on the wall post. Putting it all together with your original code:

httpMethod: 'POST',
parameters: {
  file_url: { string: media.url },
  description: { string: message || '' },
  is_explicit_share: { string: 'true' },
  ...
}

这篇关于在React Native中使用GraphRequest将mp4发布到Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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