发布视频通过URL上使用Facebook图形API的Facebook? [英] Post a video by URL on facebook using the facebook graph API?
问题描述
我有一个Facebook页面,我想上传一个视频,它是已经托管在我的服务器上。
我需要通过JavaScript来做到这一点,而我已经是视频的src链接(类似于 https://cdn.whodaman.net/Q45rt7y.mp4
)。作为管理员,我拥有所有必需的权限( publish_stream,manage_pages
)。
I have a facebook page, and I am trying to upload a video to it that is already hosted on my servers.
I need to do this via javascript, and all I have is the src link (something like https://cdn.whodaman.net/Q45rt7y.mp4
) of the video. Being the administrator, I have all required permissions (publish_stream, manage_pages
).
借助 Facebook的API 说,我要发送数据为的multipart / form-data的
这意味着视频内容。因此,要通过AJAX做到这一点,我也跟着<一个href="http://stackoverflow.com/questions/6974684/how-to-send-formdata-objects-with-ajax-requests-in-jquery">this问题的计算器,以及随后如何发送与Ajax的请求FORMDATA对象的jQuery。
The facebook api says that I have to send the data as multipart/form-data
which means the video content. So to do this via ajax, I followed this question on stackoverflow, and followed How to send FormData objects with Ajax-requests in jQuery.
下面是我的 JavaScript的code
var fd = new FormData();
fd.append( 'source', 'https://cdn.whodaman.net/Q45rt7y.mp4' );
fd.append( 'access_token', testaccessToken);
fd.append( 'title', "Test Video");
$.ajax({
url: "https://graph-video.facebook.com/"+testPageId+"/videos",
data: fd,
processData: false,
contentType: false,
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
}
});
下面是请求和相应的响应:
Here's the request and corresponding response:
Request URL:https://graph-video.facebook.com/[my page id]/videos
Request Method:POST
Status Code:400 Bad Request
Request Headers
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:948
Content-Type:multipart/form-data
Cookie: [some cookie data]
Host:graph-video.facebook.com
Origin:http://real.domain.com:8090
Pragma:no-cache
Referer:http://real.domain.com:8090/test/upload
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Request Payload
------WebKitFormBoundaryd8laVBo5HXRTFJnn
Content-Disposition: form-data; name="source"
https://cdn.whodaman.net/Q45rt7y.mp4
------WebKitFormBoundaryd8laVBo5HXRTFJnn
Content-Disposition: form-data; name="access_token"
[my access token]
------WebKitFormBoundaryd8laVBo5HXRTFJnn
Content-Disposition: form-data; name="title"
Test Video
------WebKitFormBoundaryd8laVBo5HXRTFJnn--
Response Headers
Access-Control-Allow-Origin:*
Cache-Control:no-store
Connection:keep-alive
Content-Length:146
Content-Type:application/json; charset=UTF-8
Date:Mon, 11 Nov 2013 13:50:45 GMT
Expires:Sat, 01 Jan 2000 00:00:00 GMT
Pragma:no-cache
WWW-Authenticate:OAuth "Facebook Platform" "invalid_token" "An access token is required to request this resource."
X-FB-Debug:HlhHF7eIBkLbUBktqeWnVv8V3viIeS8jom0WPt1D7fc=
X-FB-Rev:1000997
Facebook正在请求访问令牌!我是pretty的确定我有没有合适的人,因为我能够添加一个文本状态后。我也试图改变名称的文件
在表单数据参数从源
到文件
没有效果。
Facebook is asking for the access token! I'm pretty sure I have the right one, because I'm being able to add a text status post. I have also tried to change the name of the file
parameter in form data from source
to file
to no effect.
那么,这甚至可以通过视频上传到Facebook的JS SDK直接从视频网址是什么?我有一种感觉是,和上午相当接近的解决方案。
So is it even possible to upload a video to facebook via the js sdk directly from the video url? I have a feeling it is, and am quite close to the solution.
推荐答案
使用file_url字段指定网址为您的视频,摆脱了源字段进行POST请求的图形API,无需一个多/表格数据。
Perform a POST request to the graph api Using the file_url field to specify the url for your video and get rid of the source field , no need for a multipart/form-data .
这篇关于发布视频通过URL上使用Facebook图形API的Facebook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!