问题
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();
});
And here is the 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' } },
],
}
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.
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):
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!
回答1:
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.
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.
Here's some more information on the video upload process: https://developers.facebook.com/docs/graph-api/video-uploads
To start you off, make sure to use the /videos
endpoint rather than /feed
:
new GraphRequest('/me/videos'
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
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' },
...
}
来源:https://stackoverflow.com/questions/47293576/posting-mp4-to-facebook-using-graphrequest-in-react-native