2016-03-22 2 views
0

Ich versuche, ein Video auf YouTube hochladen von YouTube Daten API verwenden, aus meiner Anwendung aber leider ist die API, die es Entwicklern von YouTube bereitgestelltYouTube Data API für das Hochladen von Arbeits Videos nicht in mvc

https://developers.google.com/youtube/v3/code_samples/dotnet#upload_a_video

funktioniert nicht vor drei Wochen Ich testete den Code und es funktionierte gut, aber jetzt, wenn ich versuche, es in meiner Anwendung verwenden es verursacht ein Problem der gesamte Code funktioniert gut, aber wenn der Video-Upload-Prozess gestartet wird es geladen wird und laden und das video nicht hochgeladen ich google es aber keine hilfe finden. wenn jemand mir helfen kann? hier ist mein Code, die ich

private async Task Run() 
     { 
      UserCredential credential; 
      using (var stream = new FileStream("G:\\client_secret_783534382593-0cn4gm229raqq97kdu0ghsj9hqfsc5o1.apps.googleusercontent.com.json", FileMode.Open, FileAccess.Read)) 
      { 
       credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets, 
        // This OAuth 2.0 access scope allows an application to upload files to the 
        // authenticated user's YouTube channel, but doesn't allow other types of access. 
        new[] { YouTubeService.Scope.YoutubeUpload }, 
        "user", 
        CancellationToken.None 
       ); 
      } 

      var youtubeService = new YouTubeService(new BaseClientService.Initializer() 
      { 
       HttpClientInitializer = credential, 
       ApplicationName = Assembly.GetExecutingAssembly().GetName().Name 
      }); 

      var video = new Video(); 
      video.Snippet = new VideoSnippet(); 
      video.Snippet.Title = "ttry"; 
      video.Snippet.Description = " Video Description"; 
      video.Snippet.Tags = new string[] { "tag1s", "tag2s" }; 
      video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list 
      video.Status = new VideoStatus(); 
      video.Status.PrivacyStatus = "public"; // or "private" or "publi 
      var filePath = "F:\\Dna.MP4"; // Replace with path to actual movie file. 

      using (var fileStream = new FileStream(filePath, FileMode.Open)) 
      { 
       var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*"); 
       videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged; 
       videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived; 

       await videosInsertRequest.UploadAsync(); 
      } 
     } 

     void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress) 
     { 
      switch (progress.Status) 
      { 
       case UploadStatus.Uploading: 
        Console.WriteLine("{0} bytes sent.", progress.BytesSent); 
        break; 

       case UploadStatus.Failed: 
        Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception); 
        break; 
      } 
     } 

     void videosInsertRequest_ResponseReceived(Video video) 
     { 
      Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id); 
     } 
    } 
} 

verwende und ich bin einfach aus dieser Aktion

public ActionResult Contact() 
     { 
      Run().Wait(); 

      return View(); 
     } 

Ich frage mich ruft, warum ist es nicht funktioniert? wenn ich es debugge dann sind alle dinge und parameter in Ordnung sogar anmelde sind auch in ordnung aber am ende die datei wird nicht hochgeladen auch ich wähle 1 MB datei und ich habe auch alle notwendigen NuGet-pakete freundlicherweise einige eine hilfe mir bitte?

Antwort

1

wird das Problem durch einfaches lösen in Get-Funktion

einige Stück Code, das Hinzufügen
public async Task<ActionResult> Contact() 
{ 
    await Run(); 
    return View(); 
} 
Verwandte Themen