I'm trying to work with Google Sheets API with Xamarin Forms but I'm facing with problems reading the client_secret.json file that is used to authenticate with Google as it does when programming with .NET. When executing the following lines:
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{ ... }
I'm getting an error showing that can't find the file client_secret.json. I'm putting the property for that file in my solution making it to copy to directory with the "Always Copy" option, but no luck with this. (I'm using Visual Studio 2017).
Can anybody help me with this issue? Thank you.
Updated: The code I use is the following (any help would be appreciated):
AssetManager assets = Android.App.Application.Context.Assets;
var path = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), @"client_secret.json");
using (var asset = assets.Open("client_secret.json"))
using (var dest = System.IO.File.Create(path))
asset.CopyTo(dest);
using (var stream = assets.Open(@"client_secret.json"))
{
var secrets = GoogleClientSecrets.Load(stream).Secrets;
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, "sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}