【问题标题】:How do I figure out where my serviceaccountpath is?如何确定我的 serviceaccountpath 在哪里?
【发布时间】:2019-03-03 10:34:34
【问题描述】:

我正在尝试根据 https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/auth/src/auth_cloud_explicit.php 在代码中进行身份验证,但我不知道将什么作为 $serviceAccountPath 传递。我将私有 .json 文件复制到我的应用程序文件夹的根目录中。我需要在这里使用什么?

function auth_cloud_explicit($projectId, $serviceAccountPath)
{
    # Explicitly use service account credentials by specifying the private key
    # file.
    $config = [
        'keyFilePath' => $serviceAccountPath,
        'projectId' => $projectId,
    ];
    $storage = new StorageClient($config);
    # Make an authenticated API request (listing storage buckets)
    foreach ($storage->buckets() as $bucket) {
        printf('Bucket: %s' . PHP_EOL, $bucket->name());
    }
}

【问题讨论】:

    标签: php google-cloud-platform google-cloud-storage google-cloud-functions


    【解决方案1】:

    我认为$serviceAccountPath 应该包含您的 json 配置文件的本地路径(从 Google 控制台下载)

    【讨论】:

      【解决方案2】:

      考虑到您已经将“private.json”文件复制到应用程序目录的根目录。您应该考虑到您为 $serviceAccountPath 提供的本地路径应该始终与您希望导航到的应用程序文件的路径相关。例如,如果文件位于应用程序的根目录中,则可以使用“./private.json”。这意味着当您在 Google Cloud Platform 上部署应用程序时,您在代码中提供的指向本地驱动器(c://、F:// 等)的所有路径都将不再有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-29
        • 2018-04-20
        • 1970-01-01
        • 2010-10-03
        • 1970-01-01
        • 2018-12-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多