GoogleドライブAPIを初めて使用していますが、コンテンツとして1行にバージョン番号のある単純なtxtファイルをダウンロードする必要があります2.5.1.0)、ファイルをダウンロードして開くと全く違うものになります。GoogleドライブAPI v3でダウンロードしたファイルの内容が異なります
また、ブラウザを使用してファイルをダウンロードしただけでは、予想されるコンテンツはありますが、アプリケーションからダウンロードした場合は表示されません。
私はこれに関する助言をいただきたいと思います。
これは、これまでの私のコードです:
private void CheckForUpdates()
{
GoogleDrive drive = new GoogleDrive();
string url = drive.GetFileURL("current.txt");
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
string tmpPath = Path.Combine(Path.GetTempPath(), "current.txt");
request.Timeout = 5000;
WebClient response = new WebClient();
response.DownloadFile(url, tmpPath);
}
public string GetFileURL(string fileName)
{
DriveService service = GetDriveService();
// Define parameters of request.
FilesResource.ListRequest listRequest = service.Files.List();
listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name, parents, properties, shared, webContentLink, webViewLink, fullFileExtension, capabilities)";
listRequest.Q = string.Format("(name contains '{0}')", fileName);
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files;
if (files.Count > 0)
{
string url = files[0].WebContentLink;
string id = files[0].Id;
return url;
}
return "";
}
private DriveService GetDriveService()
{
UserCredential credential;
DriveService service;
using (var stream = new FileStream(_pathClave, FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = _pathResult;
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Drive API service.
service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
return service;
}
これはリンクです:https://drive.google.com/uc?id=0B3P8S21qYracclVaamM2Skp4bzA&export=download
を助けるかもしれないが、私は、ファイルをダウンロードするときとそれを開いて、私は全く別の何かを得る。私たちは皆本当にあなたが何を得るのか興味があります。 – pinoyyid
ファイルの内容をすべて貼り付けることができません。長すぎます。 –
aww。それが含むかもしれない小さな手掛かりさえない?ペーストビンのリンク? – pinoyyid