本文介绍了在 Windows Phone 8.1 上使用 Graph REST API 在 Facebook 上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Windows Phone 8.1 上使用 Graph REST API 在 Facebook 上传视频,下面给出的是我的代码,它不会抛出异常但不起作用,只是卡住了执行.

var backgroundUploader = new BackgroundUploader();//var fs2 = await videoFile.OpenAsync(Windows.Storage.FileAccessMode.Read);backgroundUploader.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + "8af25ae9-b1b4-4ff7-908d-27c3fbe7d78a");backgroundUploader.Method = "POST";UploadOperation uploadOperation = backgroundUploader.CreateUpload((new Uri("https://graph-video.facebook.com/me/videos?title=Title&description=Description&access_token="+ accessToken)),视频文件);//它卡在这里,两个CreateUploadXXX方法都没有进展//UploadOperation uploadOperation = await backgroundUploader.CreateUploadFromStreamAsync//(new Uri("https://graph-video.facebook.com/me/videos?title=Title&description=Description&access_token=" + accessToken),//fs2.GetInputStreamAt(0));等待uploadOperation.StartAsync();ResponseInformation response = uploadOperation.GetResponseInformation();
解决方案

我意识到这并没有回答如何通过图表上传的问题,但作为替代方案,您可以使用共享内容上传视频:

>

 DataTransferManager dataTransferManager;私有无效 RegisterForShare(){如果(数据传输管理器 == 空){dataTransferManager = DataTransferManager.GetForCurrentView();dataTransferManager.DataRequested += new TypedEventHandler(this.ShareStorageItemsHandler);}}private async void ShareStorageItemsHandler(DataTransferManager sender, DataRequestedEventArgs e){数据请求请求 = e.Request;request.Data.Properties.Title = "这里的标题";request.Data.Properties.Description = "此处描述";//因为我们在 DataRequested 事件处理程序中进行异步调用,//我们需要先获得延迟.DataRequestDeferral 延迟 = request.GetDeferral();StorageFile videoStorageFile;//在某处设置它//确保我们总是在延迟时调用 Complete.尝试{列表storageItems = new List();storageItems.Add(videoStorageFile);request.Data.SetStorageItems(storageItems);}最后{延迟.完成();}}

然后要调出共享菜单,您需要调用:

Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();

I want to upload video on Facebook using Graph REST API on Windows Phone 8.1, below given is my code, which doesn't throw exception but not working, just stuck the execution.

var backgroundUploader = new BackgroundUploader();
//var fs2 = await videoFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

backgroundUploader.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + "8af25ae9-b1b4-4ff7-908d-27c3fbe7d78a");
backgroundUploader.Method = "POST";

UploadOperation uploadOperation = backgroundUploader.CreateUpload(
    (new Uri("https://graph-video.facebook.com/me/videos?title=Title&description=Description&access_token=" + accessToken)),
    videoFile);

//It stucks here, no progress for both CreateUploadXXX method

// UploadOperation uploadOperation = await backgroundUploader.CreateUploadFromStreamAsync
//     (new Uri("https://graph-video.facebook.com/me/videos?title=Title&description=Description&access_token=" + accessToken), 
//     fs2.GetInputStreamAt(0));


await uploadOperation.StartAsync();
ResponseInformation response = uploadOperation.GetResponseInformation();
解决方案

I realize this doesn't answer the question of how to upload via the graph but as an alternative you could use the Share content to upload a video:

 DataTransferManager dataTransferManager;
    private void RegisterForShare()
    {

        if (dataTransferManager == null)
        {
            dataTransferManager = DataTransferManager.GetForCurrentView();
            dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager,
                DataRequestedEventArgs>(this.ShareStorageItemsHandler);
        }
    }

    private async void ShareStorageItemsHandler(DataTransferManager sender, DataRequestedEventArgs e)
    {
        DataRequest request = e.Request;

        request.Data.Properties.Title = "Title Here";
        request.Data.Properties.Description = "Description Here";


        // Because we are making async calls in the DataRequested event handler,
        // we need to get the deferral first.
        DataRequestDeferral deferral = request.GetDeferral();


        StorageFile videoStorageFile; // set this somewhere


        // Make sure we always call Complete on the deferral.
        try
        {

            List<IStorageItem> storageItems = new List<IStorageItem>();
            storageItems.Add(videoStorageFile);
            request.Data.SetStorageItems(storageItems);
        }
        finally
        {
            deferral.Complete();
        }
    }

And then to bring up the share menu you will need to call:

Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();

这篇关于在 Windows Phone 8.1 上使用 Graph REST API 在 Facebook 上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 15:25