Загрузить видео с устройства iOS на YouTube Xamarin iOS - PullRequest
0 голосов
/ 05 марта 2019

// Мой код для назначения учетных данных youtubeService:

  TokenResponse token = new TokenResponse();

  token.AccessToken = e.User.Authentication.AccessToken;

  token.IssuedUtc = DateTime.Now;

  var time = e.User.Authentication.AccessTokenExpirationDate.SecondsSinceReferenceDate.ToString();  

string[] parts = time.Split('.');

int i1 = int.Parse(parts[0]);

int i2 = int.Parse(parts[1]);

token.ExpiresInSeconds = long.Parse(i1.ToString());

 ClientSecrets clientSecrets = new ClientSecrets();

clientSecrets.ClientId = e.User.Authentication.ClientId;

GoogleAuthorizationCodeFlow.Initializer initializer = new GoogleAuthorizationCodeFlow.Initializer();

initializer.ClientSecrets = clientSecrets;

credential = new UserCredential(new Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow(initializer), e.User.UserID, token);

 youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential
            });

            video.Snippet = new VideoSnippet();
            video.Snippet.Title = "Default Video Title";
            video.Snippet.Description = "Default Video Description";
            video.Snippet.Tags = new string[] { "tag1", "tag2" };
            video.Status = new VideoStatus();
            video.Status.PrivacyStatus = "private"; // or "private" or "public"
            using (var fileStream = new FileStream(pathString, FileMode.Open))
            {
                var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
                videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
                videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
                 videosInsertRequest.UploadAsync();
            }

// Но я столкнулся с проблемой при загрузке видео. Ниже приведена ошибка:

An error prevented the upload from completing.
System.FormatException: Could not parse value for header 'Content-Range'
  at System.Net.Http.Headers.HttpHeaders.AddInternal (System.String name, System.Collections.Generic.IEnumerable`1[T] values, System.Net.Http.Headers.HeaderInfo headerInfo, System.Boolean ignoreInvalid) [0x00043] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:196 
  at System.Net.Http.Headers.HttpHeaders.Add (System.String name, System.Collections.Generic.IEnumerable`1[T] values) [0x0000e] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:171 
  at System.Net.Http.Headers.HttpHeaders.Add (System.String name, System.String value) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:163 
  at Google.Apis.Upload.ResumableUpload+<SendNextChunkAsync>d__80.MoveNext () [0x000a7] in C:\Apiary\2019-01-31.11-23-48\Src\Support\Google.Apis\Upload\ResumableUpload.cs:642 
--- End of stack trace from previous location where exception was thrown ---
  at Google.Apis.Upload.ResumableUpload+<UploadCoreAsync>d__77.MoveNext () [0x0005a] in C:\Apiary\2019-01-31.11-23-48\Src\Support\Google.Apis\Upload\ResumableUpload.cs:576 

// Возможно, эта ошибка возникает при назначении учетных данных YouTubeService. Дайте мне знать, если кто-нибудь сталкивается с такой проблемой.

...