Upload video on Facebook using Graph REST API on Windows Phone 8.1

瘦欲@ 提交于 2019-12-25 02:53:51

问题


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();

回答1:


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();


来源:https://stackoverflow.com/questions/24183960/upload-video-on-facebook-using-graph-rest-api-on-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!