0
How to send a file to google drive in c#? I have an Intptr of a file, do I have to convert to bytes and upload? What would be the sending? I took a code gave m tutorial, however I did not understand which configs:
class DriveCommandLineSample
{
static void Main(string[] args)
{
String CLIENT_ID = "YOUR_CLIENT_ID";
String CLIENT_SECRET = "YOUR_CLIENT_SECRET";
// Register the authenticator and create the service
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
{
Authenticator = auth
});
File body = new File();
body.Title = "My document";
body.Description = "A test document";
body.MimeType = "text/plain";
byte[] byteArray = System.IO.File.ReadAllBytes("document.txt");
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
request.Upload();
File file = request.ResponseBody;
Console.WriteLine("File id: " + file.Id);
Console.ReadLine();
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { DriveService.Scopes.Drive.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
}
}
This client ID , and secret refers to what? in which folder will I send there?
Take a look at the
SDK
from drive toC#
-> https://developers.google.com/drive/web/quickstart/quickstart-cs– MeuChapeu
There is a tutorial on this site -> http://www.daimto.com/google-drive-api-c-upload/
– MeuChapeu
According to what you posted I mounted the code on the question, see if Voce can help me. vlw
– War Lock
Basically the data to access the
API
authentication. In the documentation ofSDK
explains how to do this. -->https://developers.google.com/drive/web/auth/web-server– MeuChapeu
at the link of
daimto.com
has the series of tutorials, gives a look at all parts of the series on theGoogle Drive
.– MeuChapeu
The google drive library does not install in visual studio 2012, because it asks for the version of the newest nuget, and only for 2013, know where I can find the . dll already compiled?
– War Lock
Unknown, already trying to update the
NuGet
?– MeuChapeu
is by the nuget I’m trying, asks for the newest version...
– War Lock
Download and install the newest version of nuget and install on VS2012. I looked on the website and the newest version of nuget runs on VS2012.
– MeuChapeu
Let’s go continue this discussion in chat.
– War Lock
I got vlw...
– War Lock
Does anyone know how to tell me why you’re stopping at request.upload() ? no exception or anything. creates the directory but no file
– War Lock