Reputation: 2564
I'm uploading files to Google Drive following the tutorial found here:
https://developers.google.com/drive/web/quickstart/quickstart-cs
I have created an Id and Secret for my main account, and with that info, I could upload to any of my two accounts (deleting the authentication token from %AppData%/Google...).
However, a client gave us his google account so we can try that everything would work for him, it didn't work for his account. We can upload and download files through the web interface without any problem, but it doesn't work with my app.
One difference I noticed is that my client's account didn't have a google e-mail address; it was [email protected], so I created a new google account with my work e-mail address, tested it, and it worked flawlessly after just loggin into Google Drive.
The problem arises in the last lines:
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
request.Upload();
File file = request.ResponseBody;
Console.WriteLine("File id: " + file.Id);
At that point, request.ResponseBody is null so, if I just run the code, file.Id throws an ArgumentNullException. If I break into debug mode and examine the environment instead, request.Progress (private property from a base class) has its Status field set to "Failed", and the Exception field is a ArgumentNullException, with the message "Argument can not be null. Argument name: baseUri.".
Any idea about what could be wrong?
Update: The code to create the service object:
// Create the service.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API Sample",
});
Upvotes: 1
Views: 1291
Reputation: 83
you have an OAuth Token without the correct Scope!
Set you Scope to:
static string[] Scopes = { DriveService.Scope.Drive, DriveService.Scope.DriveFile };
In my first attempts, i used only Drive
and not DriveFile
Upvotes: 2
Reputation:
I solved the exact same error with the following steps:
It should then be under the tab "Activated APIs" and this error is gone.
Upvotes: 0
Reputation: 60
I got the same issue and finally I found the API is not enabled. I reply the cause in my case, and hope it helps you.
In my case I does not configure API setting correctly.
The reason why ArgumentNullException is thrown when API is not configured correctly is reported issue. https://code.google.com/p/google-api-dotnet-client/issues/detail?id=421
The first request in ResumableUpload.InitializeUpload got error, but the error message included "API is not configured correctly" is not reported.
Upvotes: 0