使用Facebook图表API在Facebook上通过网址发布视频 [英] Post a video by URL on facebook using the facebook graph API?

查看:155
本文介绍了使用Facebook图表API在Facebook上通过网址发布视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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-数据这意味着视频内容。所以要通过ajax这样做,我遵循这个问题在stackoverflow上,并遵循如何在jQuery中使用Ajax请求发送FormData对象。

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代码


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正在要求访问令牌!我确定我有一个正确的,因为我可以添加一个文本状态的帖子。我还尝试将表单数据中的文件的名称从 source 更改为文件不起作用。

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.

甚至可以通过js sdk直接从视频网址上​​传视频到Facebook?我有一种感觉,而且非常接近解决方案。

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.

推荐答案

对图表执行POST请求api使用file_url字段指定您的视频的网址,并摆脱源字段,不需要多部分/表单数据。

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 .

这篇关于使用Facebook图表API在Facebook上通过网址发布视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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