asp .Net MVCで初めて誰かがGoogleドキュメントAPIリフレッシュトークンを取得するのを手伝ってもらえますか?クライアントIdとクライアントSecreteがあります。リフレッシュトークンを取得する方法とリフレッシュトークンを取得する方法は、ドライブのGoogle APIにアクセスするためのアクセストークンを取得する方法です。Asp.Net MVCを使用してgoogle docs api refreshトークンとアクセストークンを取得
答えて
彼らはまだDrive API V3のサンプルコードで多くのことをしていません。私はこれらのスコープのすべてを使用しないで、あなたがこのコードを必要とするものを事前に生成します。
NuGetパッケージ
/// <summary>
/// This method requests Authentication from a user using Oauth2.
/// Credentials are stored in System.Environment.SpecialFolder.Personal
/// Documentation https://developers.google.com/accounts/docs/OAuth2
/// </summary>
/// <param name="clientSecretJson">Path to the client secret json file from Google Developers console.</param>
/// <param name="userName">Identifying string for the user who is being authentcated.</param>
/// <returns>DriveService used to make requests against the Drive API</returns>
public static DriveService AuthenticateOauth(string clientSecretJson, string userName)
{
try
{
if (string.IsNullOrEmpty(userName))
throw new Exception("userName is required.");
if (!File.Exists(clientSecretJson))
throw new Exception("clientSecretJson file does not exist.");
// These are the scopes of permissions you need. It is best to request only what you need and not all of them
string[] scopes = new string[] { DriveService.Scope.Drive, // View and manage the files in your Google Drive
DriveService.Scope.DriveAppdata, // View and manage its own configuration data in your Google Drive
DriveService.Scope.DriveFile, // View and manage Google Drive files and folders that you have opened or created with this app
DriveService.Scope.DriveMetadata, // View and manage metadata of files in your Google Drive
DriveService.Scope.DriveMetadataReadonly, // View metadata for files in your Google Drive
DriveService.Scope.DrivePhotosReadonly, // View the photos, videos and albums in your Google Photos
DriveService.Scope.DriveReadonly, // View the files in your Google Drive
DriveService.Scope.DriveScripts}; // Modify your Google Apps Script scripts' behavior
UserCredential credential;
using (var stream = new FileStream(clientSecretJson, FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/apiName");
// Requesting Authentication or loading previously stored authentication for userName
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
scopes,
userName,
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Drive API service.
return new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive Authentication Sample",
});
}
catch (Exception ex)
{
Console.WriteLine("Create Oauth2 DriveService failed" + ex.Message);
throw new Exception("CreateOauth2DriveFailed", ex);
}
}
サービスアカウントJSONキーファイルはありませんp12の
/// <summary>
/// Authenticating to Google using a Service account
/// Documentation: https://developers.google.com/accounts/docs/OAuth2#serviceaccount
///
/// Note: Not all APIs support service accounts I cant garentee this will work. If you find an api that doesnt support service accoutns contact me
/// me at www.daimto.com and I will remove it from auto genration of this APIs sample project.
/// </summary>
/// <param name="serviceAccountEmail">From Google Developer console https://console.developers.google.com</param>
/// <param name="serviceAccountCredentialFilePath">Location of the Json Service account key file downloaded from Google Developer console https://console.developers.google.com</param>
/// <returns>DriveService used to make requests against the Drive API</returns>
public static DriveService AuthenticateServiceAccount(string serviceAccountCredentialFilePath)
{
try
{
if (string.IsNullOrEmpty(serviceAccountCredentialFilePath))
throw new Exception("Path to the .JSon service account credentials file is required.");
if (!File.Exists(serviceAccountCredentialFilePath))
throw new Exception("The service account credentials .JSon file does not exist at:" + serviceAccountCredentialFilePath);
// These are the scopes of permissions you need. It is best to request only what you need and not all of them
string[] scopes = new string[] { DriveService.Scope.Drive, // View and manage the files in your Google Drive
DriveService.Scope.DriveAppdata, // View and manage its own configuration data in your Google Drive
DriveService.Scope.DriveFile, // View and manage Google Drive files and folders that you have opened or created with this app
DriveService.Scope.DriveMetadata, // View and manage metadata of files in your Google Drive
DriveService.Scope.DriveMetadataReadonly, // View metadata for files in your Google Drive
DriveService.Scope.DrivePhotosReadonly, // View the photos, videos and albums in your Google Photos
DriveService.Scope.DriveReadonly, // View the files in your Google Drive
DriveService.Scope.DriveScripts}; // Modify your Google Apps Script scripts' behavior
Stream stream = new FileStream(serviceAccountCredentialFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
var credential = GoogleCredential.FromStream(stream).CreateScoped(scopes);
// Create the Drive service.
return new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive Authentication Sample",
});
}
catch (Exception ex)
{
Console.WriteLine("Create service account DriveService failed" + ex.Message);
throw new Exception("CreateServiceAccountDriveServiceFailed", ex);
}
}
は、私が持っているあなたが何かを必要とするなら、私を知ってみましょう部分的なサンプルプロジェクトが構築されました。
ありがとうDalmTo。私はUserCredentialとDriveServiceを正常に取得しました。私のサイト訪問者がGoogleドライブにファイルをアップロードできる可能性があることを教えてください。私はバックグラウンドでoauthを認証します。だから私はこれをどのように達成できますか?ユーザーがあなたのアカウントにアップロードできるようにするには、 –
Oauth2ではなくサービスアカウントの使用を検討する必要があります。その後、ドライブアカウントのフォルダをサービスアカウントと共有できます。サービスアカウントはダミーユーザーの一種で、サービスアカウントはドライブフォルダーにアップロードできます。サービスアカウントはアップロード後にアクセス許可を与えるためにファイルのアクセス許可を更新する必要があります。アクセス権がありません。 – DaImTo
を入力する前に、サービスアカウント認証のためのコードをいくつか追加してください。と私のチュートリアルサービスアカウントについては、あなたがコンセプトを理解しているので、http://www.daimto.com/google-developer-console-service-account/ – DaImTo
- 1. メールアドレスとパスワードを使用してLinkedin APIへのアクセストークンを取得
- 2. Refreshトークンを使用してBox APIにアクセスする
- 3. Googleログイン新しいGoogleSignInOptionsを使用してアクセストークンを取得
- 4. asp.netのgmail apiの更新トークンからアクセストークンを取得する方法
- 5. Oauthトークンを使用してGoogleアナリティクスデータを取得しますか?
- 6. アクセストークンを使用して電子メールアドレスを取得するGoogle Ionic
- 7. Asp.net mvcとgoogle api
- 8. OneDrive APIを使用してアクセストークンを取得する
- 9. Google Docsビューア用API
- 10. iphone google docs api issue
- 11. Refresh asp.net mvcページ
- 12. asp.netウェブサイトでgoogle docs APIを使用する
- 13. Google Plus APIのOAuthアクセストークンの取得
- 14. xamarin.authを使用してgoogle apiの更新トークンを取得する
- 15. asp.netアプリケーションでgoogle docsを使用する
- 16. MVCアプリケーションでアクセストークンを取得
- 17. OWINを使用してASP.NET MVC 5アプリでFacebookのアクセストークンを保存して取得します
- 18. Refresh div(jquery + asp.net mvc)
- 19. Google APIを使用してトークンを取得できません[google-oauth-java-client-1.12.0-beta]
- 20. ASP.NET ID(IdentityServer4を使用)外部リソースoauthアクセストークンを取得
- 21. FacebookのグラフAPIを使用して長期アクセストークンを取得できません
- 22. asp.netアプリケーションからbox APIからアクセストークンを取得しますか?
- 23. instagram APIのアクセストークンを取得
- 24. Google api oauthアクセストークンを使用しているときに[PHP]エラー401トークンが無効です
- 25. googleドライブAPI v3を使用してGoogleドキュメントのファイルコンテンツを取得
- 26. Google + API/Google People APIを使用してGoogle Plusフレンドリストを取得するiOS
- 27. Google Docs API with Python
- 28. Google Apiのアクセスと更新トークンの取得
- 29. GoogleサービスアカウントでNullとしてアクセストークンを取得する
- 30. GitLab refresh oAuthトークン
GoogleドキュメントAPIのどのバージョンを調べましたか? – DaImTo
私はgoogle api v3を使用しました。 –
私はまだGoogleドキュメントAPIは実際には物事ではないので、GoogleドライブAPIを意味すると仮定しています – DaImTo