【问题标题】:Upload photos to Google Photos API - Error 500将照片上传到 Google Photos API - 错误 500
【发布时间】:2018-07-29 02:37:08
【问题描述】:

我在尝试将媒体上传到 Google Photos API 时遇到以下错误,遵循 the docs

这就是我检索字节数组的方式:

这就是我提出请求的方式:

我尝试了很多东西,但都没有奏效......

注意:我正在使用其他 Google Photos API 端点,例如获取相册、创建相册、获取媒体,一切都按预期工作。上传媒体是我唯一遇到的问题。

注意2:令牌发送正确。

注意 3:所有原始端点都在 google 控制台(包括本地主机)中配置得如此之多,以至于其他端点都可以正常工作。

谁能给我一盏灯?

【问题讨论】:

    标签: ajax filereader google-photos google-photos-api


    【解决方案1】:

    我正在用 C# 编写类似的东西,并且能够使用照片 api。我最好的建议是仔细检查标题。我希望这会有所帮助,另外我添加了一个成功调用 api 的邮递员截图:

    public async Task<GoogleApiResponse> UploadPhoto(StorageFile photo)
            {
                var userInfo = UserInfoVault.GetUserInfo();
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userInfo.AccessToken);
                client.DefaultRequestHeaders.Add("X-Goog-Upload-File-Name", photo.DisplayName);
    
                var fileStream = await photo.OpenAsync(FileAccessMode.Read);
                var reader = new DataReader(fileStream.GetInputStreamAt(0));
                await reader.LoadAsync((uint)fileStream.Size);
                byte[] pixels = new byte[fileStream.Size];
                reader.ReadBytes(pixels);
    
                var httpContent = new ByteArrayContent(pixels);
                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
    
                HttpResponseMessage photoResponse = client.PostAsync(ApiEdnpoints.UploadPhoto, httpContent).Result;
                string strResponse = await photoResponse.Content.ReadAsStringAsync();
    
                return null;
            }

    Postman screenshot of successful call to upload a photo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-04
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多