Created
August 1, 2017 15:03
-
-
Save kiranmaya/cbcfe8c29079b2ed5b13fe2a48aeddad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string ApplicationName = "Google Sheets API .NET Quickstart"; | |
string url = "https://docs.google.com/spreadsheets/d/1FTbqxgf1qdgXdPIQFgOg9cjzHP827S2gkpGy1kwJ6Cw/edit#gid=0"; | |
public fbEth() | |
{ | |
} | |
public Dualdata getData() | |
{ | |
Dualdata data = new Dualdata(); | |
UserCredential credential; | |
using (var stream = | |
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) | |
{ | |
string credPath = System.Environment.GetFolderPath( | |
System.Environment.SpecialFolder.Personal); | |
credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json"); | |
credential = GoogleWebAuthorizationBroker.AuthorizeAsync( | |
GoogleClientSecrets.Load(stream).Secrets, | |
Scopes, | |
"user", | |
CancellationToken.None, | |
new FileDataStore(credPath, true)).Result; | |
Console.WriteLine("Credential file saved to: " + credPath); | |
} | |
// Create Google Sheets API service. | |
var service = new SheetsService(new BaseClientService.Initializer() | |
{ | |
HttpClientInitializer = credential, | |
ApplicationName = ApplicationName, | |
}); | |
// Define request parameters. | |
String spreadsheetId = "1FTbqxgf1qdgXdPIQFgOg9cjzHP827S2gkpGy1kwJ6Cw"; | |
String range = "Live Price"; | |
SpreadsheetsResource.ValuesResource.GetRequest request = | |
service.Spreadsheets.Values.Get(spreadsheetId, range); | |
ValueRange response = request.Execute(); | |
IList<IList<Object>> values = response.Values; | |
if (values != null && values.Count > 0) | |
{ | |
data.buy = values[1][2].ToString().Remove(0, 1).Replace(",", ""); //buy | |
data.sell = values[5][2].ToString().Remove(0, 1).Replace(",", "");//sell | |
} | |
else | |
{ | |
Console.WriteLine("No data found."); | |
} | |
return data; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment