Skip to content

Commit

Permalink
side study for google data studio with app wide credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
dnenov committed May 19, 2019
1 parent 77d4249 commit ac088bd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.userosscache
*.sln.docstates
credentials.json
dynamosheets.json

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
8 changes: 6 additions & 2 deletions Binoculars.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<None Include="credentials.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="dynamosheets.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="pkg.json" />
</ItemGroup>
Expand Down Expand Up @@ -160,6 +163,7 @@
<SourcePdbs Include="$(TargetDir)*.pdb" />
<SourcePkg Include="$(ProjectDir)pkg.json" />
<SourcePkg Include="$(ProjectDir)credentials.json" />
<SourcePkg Include="$(ProjectDir)dynamosheets.json" />
<SourceExtension Include="$(TargetDir)*ExtensionDefinition.xml" />
</ItemGroup>
<!--Delete any previous build folder -->
Expand All @@ -176,9 +180,9 @@
</ItemGroup>
<PropertyGroup>
<!--Copy to Dynamo sandbox for testing -->
<DeployFolder Condition="'$(Configuration)' == 'Debug' Or '$(Configuration)' == 'Release'">$(AppData)\Dynamo\Dynamo Core\2.0\packages\$(ProjectName)</DeployFolder>
<DeployFolder Condition="'$(Configuration)' == 'Debug' Or '$(Configuration)' == 'Release'">$(AppData)\Dynamo\Dynamo Core\2.1\packages\$(ProjectName)</DeployFolder>
<!--Copy to Dynamo revit for publishing -->
<DeployFolder Condition="'$(Configuration)' == 'DebugRevit'">$(AppData)\Dynamo\Dynamo Revit\2.0\packages\$(ProjectName)</DeployFolder>
<DeployFolder Condition="'$(Configuration)' == 'DebugRevit'">$(AppData)\Dynamo\Dynamo Revit\2.1\packages\$(ProjectName)</DeployFolder>
</PropertyGroup>
<!--Delete any previous package directory with same name -->
<RemoveDir Directories="$(DeployFolder)" />
Expand Down
29 changes: 27 additions & 2 deletions Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,36 @@ public static class ExportSheets

public static void Execute(IList<IList<object>> list)
{
UserCredential credential;
//UserCredential credential;
string assembly = Utils.AssemblyDirectory;
string file = "credentials.json";
string file = "dynamosheets.json";
//string file = "credentials.json";
string path = Path.GetFullPath(Path.Combine(assembly, @"..\", file));
string credPath = Path.GetFullPath(Path.Combine(assembly, @"..\", "token.json"));

//var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);

ServiceAccountCredential credential;

string[] Scopes = { SheetsService.Scope.Spreadsheets };
string serviceAccountEmail = "binocularsserviceaccount@quickstart-1554479480474.iam.gserviceaccount.com";

using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = (ServiceAccountCredential)
GoogleCredential.FromStream(stream).UnderlyingCredential;

var initializer = new ServiceAccountCredential.Initializer(credential.Id)
{
User = serviceAccountEmail,
Key = credential.Key,
Scopes = Scopes
};
credential = new ServiceAccountCredential(initializer);
}


/*
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
// The file token.json stores the user's access and refresh tokens, and is created
Expand All @@ -129,6 +153,7 @@ public static void Execute(IList<IList<object>> list)
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
*/

// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
Expand Down

0 comments on commit ac088bd

Please sign in to comment.