如何使用Facebook图形API上传视频

时间:2015-12-17 10:26:07

标签: facebook facebook-graph-api

我已经挣扎了好几个星期才弄清楚如何使用图表api上传视频。我已经阅读了所有文档,我只是不明白在编写代码之前我必须做些什么才能从图形api中获得正确的响应。我已经包含了一张图片。

有人可以像孩子一样告诉我我必须准备好什么吗?

enter image description here

2 个答案:

答案 0 :(得分:0)

弄清楚如何使用带有c#的图形api来实现统一。

您可以发表评论并发布视频。 给出的网址只是一个可用的开放视频,如果您愿意,可以选择自己的视频,或者将来无法使用。

享受!

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;
using Facebook.MiniJSON;

public class FBVideoPost : MonoBehaviour {

    // Use this for initialization
    void Start () {

        // this is to post string
        postStatus ();

        //this is to post video
        this.StartCoroutine(this.StartVideoUpload());
    }

    void postStatus()
    {
        var formdata = new Dictionary<string, string>();
        formdata.Add ("message", "This is my third post!");
        FB.API("/me/feed", HttpMethod.POST, delegate (IGraphResult callback){
            Debug.Log ("This is a test!");
        },formdata);
    }

    private IEnumerator StartVideoUpload()
    {
        yield return new WaitForEndOfFrame();

        WWW www = new WWW("http://techslides.com/demos/sample-videos/small.mp4");
        while(!www.isDone) {
            yield return null;
            Debug.Log("progress : "+www.progress);
        }
        Debug.Log("size : "+www.size);
        var wwwForm = new WWWForm();
        wwwForm.AddBinaryData("file", www.bytes, "Video.MOV","multipart/form-data");
        wwwForm.AddField("title", "Hello World");
        wwwForm.AddField("description", "How you doing?");

        FB.API("me/videos", HttpMethod.POST, UploadFinish, wwwForm);
    }

    private void UploadFinish(IGraphResult result) {
        Debug.Log("result : "+result.ToString()+" , error : "+result.Error);
    }
}

答案 1 :(得分:0)

我会发布另一个你自己回答的论坛帖子,除了你的答案之外,还帮助了​​我。

http://answers.unity3d.com/questions/1167534/how-to-send-file-local-path-using-wwwform-on-ios-a.html

简而言之,对于任何想要“使用来自iOS的FB SDK上传视频”的人,请按照Luke的回答添加以下内容:

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;
using Facebook.MiniJSON;

public class FBVideoPost : MonoBehaviour {

   // Use this for initialization
   void Start () {

    // this is to post string
    postStatus ();

    //this is to post video
    this.StartCoroutine(this.StartVideoUpload());
}

 void postStatus()
 {
    var formdata = new Dictionary<string, string>();
    formdata.Add ("message", "This is my third post!");
    FB.API("/me/feed", HttpMethod.POST, delegate (IGraphResult callback){
        Debug.Log ("This is a test!");
    },formdata);
 }

 private IEnumerator StartVideoUpload()
 {
     yield return new WaitForEndOfFrame();

     ///ADD THIS 

     //this is the path to your file.          
     String VideoLocStr = Application.persistentDataPath + "Your_Video.mov"
     String pathForIOS = VideoLocStr.Replace (" ","%20");
     WWW www = new WWW(pathForIOS);

     ///

     while(!www.isDone) {
        yield return null;
        Debug.Log("progress : "+www.progress);
    }
     Debug.Log("size : "+www.size);
     var wwwForm = new WWWForm();
     wwwForm.AddBinaryData("file", www.bytes, "Your_Video.mov","multipart/form-data");
     wwwForm.AddField("title", "Hello World");
     wwwForm.AddField("description", "How you doing?");

     FB.API("me/videos", HttpMethod.POST, UploadFinish, wwwForm);
 }

 private void UploadFinish(IGraphResult result) {
    Debug.Log("result : "+result.ToString()+" , error : "+result.Error);
 }
}

谢谢,卢克。

祝大家好运。