代码 403:"The request is missing a valid API key." PERMISSION_DENIED 服务帐户密钥 Google Cloud Vision PHP
Code 403 : "The request is missing a valid API key." PERMISSION_DENIED Service Account Key Google Cloud Vision PHP
我想使用服务密钥通过 ImageAnnotator 实现 Google Cloud Vision。我尝试的是如下所示:
错误:
Message: {
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
当尝试此代码时:
defined('BASEPATH') OR exit('No direct script access allowed');
use Google\Cloud\Vision\VisionClient;
class Admin_center extends CI_Controller {
function __construct() {
parent::__construct();
include APPPATH . 'third_party/vendor/autoload.php';
}
public function index() {
$this->load->view('index');
}
function upload_ocr_image() {
$img_data = $this->upload->data();
$vision = new VisionClient(['keyfile' => json_decode(file_get_contents(base_url().'assets/google_cloud_vision/credentials.json'), true)]);
$imageRes = fopen($img_data['full_path'], 'r');
$image = $vision->image($imageRes,['Text_Detection']);
$result = $vision->annotate($image);
print_r($result);
}
}
我使用了 服务帐户 密钥。
为什么我收到错误:403 Permissin Denied and Missing a valid API Key?
已编辑:
我已经按照这个 youtube 教程学习了:
https://www.youtube.com/watch?v=K-tpjOT7k-o
https://www.youtube.com/watch?v=PqAXE67fwu8&t=2s
谢谢
只需将 'credentials.json'
替换为实际文件的路径...它找不到类似的文件。
经过 5 小时的努力找到问题,终于成功了。
实际上我在上面发布的代码是有效的。
我只是输错了数组名称。
所以这一行:
$vision = new VisionClient(['keyfile' => json_decode(file_get_contents(base_url().'assets/google_cloud_vision/credentials.json'), true)])
'keyfile' 应该是 'keyFile' 而 'F' 是大写。
就这些了。
谢谢你的帮助..
我想使用服务密钥通过 ImageAnnotator 实现 Google Cloud Vision。我尝试的是如下所示:
错误:
Message: { "error": { "code": 403, "message": "The request is missing a valid API key.", "status": "PERMISSION_DENIED" } }
当尝试此代码时:
defined('BASEPATH') OR exit('No direct script access allowed');
use Google\Cloud\Vision\VisionClient;
class Admin_center extends CI_Controller {
function __construct() {
parent::__construct();
include APPPATH . 'third_party/vendor/autoload.php';
}
public function index() {
$this->load->view('index');
}
function upload_ocr_image() {
$img_data = $this->upload->data();
$vision = new VisionClient(['keyfile' => json_decode(file_get_contents(base_url().'assets/google_cloud_vision/credentials.json'), true)]);
$imageRes = fopen($img_data['full_path'], 'r');
$image = $vision->image($imageRes,['Text_Detection']);
$result = $vision->annotate($image);
print_r($result);
}
}
我使用了 服务帐户 密钥。
为什么我收到错误:403 Permissin Denied and Missing a valid API Key?
已编辑:
我已经按照这个 youtube 教程学习了:
https://www.youtube.com/watch?v=K-tpjOT7k-o
https://www.youtube.com/watch?v=PqAXE67fwu8&t=2s
谢谢
只需将 'credentials.json'
替换为实际文件的路径...它找不到类似的文件。
经过 5 小时的努力找到问题,终于成功了。
实际上我在上面发布的代码是有效的。 我只是输错了数组名称。
所以这一行:
$vision = new VisionClient(['keyfile' => json_decode(file_get_contents(base_url().'assets/google_cloud_vision/credentials.json'), true)])
'keyfile' 应该是 'keyFile' 而 'F' 是大写。
就这些了。
谢谢你的帮助..