2

Hi I'm creating a desktop application with unity to take a photo and upload it to a public google drive account. I have followed the instructions to create the project in google cloud of this page:

https://developers.google.com/drive/api/v3/quickstart/dotnet

And I've used the unity package from this repository, also following the instructions:

https://github.com/Elringus/UnityGoogleDrive

The problem is that when I try to access from my program to unity for upload the photo to the repository I get this error:

Authorization Error

Error 400: redirect_uri_mismatch

You can't log in to this app because it doesn't comply with Google's OAuth 2.0 policy.

If you are the developer of the application, register the redirect URI in the Google Cloud console. Learn more Request Details The content in this section has been provided by the app developer. This content has not been reviewed or verified by Google. If you're the app developer, make sure that these request details comply with Google policies. redirect_uri: http: // localhost: 54201

But I have already set the URLs to Authorized redirect URIs from Google Cloud, however in the error shows me the url of my localhost changes in each request (example: redirect_uri: http://localhost:59708 and redirect_uri: http://localhost:55683), so I would appreciate it if you would help me to know which url I should set on Google Cloud or how I can configure that my url doesn't change in every request.

In add I can't change the project to webgl or mobile as android, so this is a solution only for a desktop app in unity.That means than I've .json credentials from google cloud.

This my C # code that I'm using in unity.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityGoogleDrive;
using System.IO;


public class UploadGoogle : MonoBehaviour
{

    public string UploadFilePath;

    private GoogleDriveFiles.CreateRequest request;
    private string result;
   
    public void OnButtonClick()
    {
        UploadFilePath = string.Format("{0}/Snapshots/snap.jpg", Application.dataPath);
        var content = File.ReadAllBytes(UploadFilePath);

        var file = new UnityGoogleDrive.Data.File { Name = "Image.jpg", Content = content };
        GoogleDriveFiles.Create(file).Send();
        request = GoogleDriveFiles.Create(file);
        request.Fields = new List<string> { "id", "name", "size", "createdTime" };
        request.Send().OnDone += PrintResult;
    }

    private void PrintResult(UnityGoogleDrive.Data.File file)
    {
        result = string.Format("Name: {0} Size: {1:0.00}MB Created: {2:dd.MM.yyyy HH:MM:ss}\nID: {3}",
                file.Name,
                file.Size * .000001f,
                file.CreatedTime,
                file.Id);
    }

}


Thank you

Hamid Yusifli
  • 9,688
  • 2
  • 24
  • 48
Zaa
  • 21
  • 2

0 Answers0