【发布时间】:2019-02-13 12:18:34
【问题描述】:
我的目标是在我的自定义网站中加载 Google Jobs 搜索结果。 因此,我在 google 上创建了帐户并启用了Google Talent API。在谷歌云 API 帐户上启用计费后,他们允许我使用 API 密钥和服务帐户凭据向此 API 请求。
我目前正在使用 PHP 和 api-client-php 库。
为此,我已从 google Console Talent Platform 下载凭据 (client_secret.json) 的 .json 文件。
这是我的 PHP 示例代码。
require 'vendor/autoload.php';
// Instantiate the client
$client = new Google_Client();
$api_key = 'AdsadsIzaSyBYAMxEPPasdadadw5VHITCdREQW7WYeIGs8jRlUYqlzLM';
$client->setDeveloperKey($api_key);
$client->setAuthConfig(getcwd() . '/client_secret.json');
$client->setScopes(array(
'https://www.googleapis.com/auth/jobs',
'https://www.googleapis.com/auth/cloud-platform'
));
$jobs = new Google_Service_JobService($client);
$location='USA';
// Set the Metadata
$requestMetadata = new Google_Service_JobService_RequestMetadata();
$requestMetadata->setUserId('000aaaa');
$requestMetadata->setSessionId('000aaaa-1212-21212');
$requestMetadata->setDomain('www.google.com');
$jobQuery = new Google_Service_JobService_JobQuery();
$keyword='software OR java';
$jobQuery->setQuery($keyword);
// Search Job Request
$searchRequest = new Google_Service_JobService_SearchJobsRequest();
$searchRequest->setRequestMetadata($requestMetadata);
$searchRequest->setQuery($jobQuery);
$searchRequest->setMode('JOB_SEARCH');
$jobService = new Google_Service_JobService($client);
$response = $jobService->jobs->search($searchRequest);
echo "<pre>";
print_r($response);
print_r($response->matchingJobs);
在发送这个请求时,我们得到了 matchjobs 空白数组,但 $response 有一些对象数组。这就像不输出,而只是请求信息。
这是迄今为止我们使用人才搜索 API 得到的响应。
Google_Service_JobService_SearchJobsResponse Object
(
[collection_key:protected] => matchingJobs
[appliedCommuteFilterType:protected] => Google_Service_JobService_CommutePreference
[appliedCommuteFilterDataType:protected] =>
[appliedJobLocationFiltersType:protected] => Google_Service_JobService_JobLocation
[appliedJobLocationFiltersDataType:protected] => array
[estimatedTotalSize] =>
[histogramResultsType:protected] => Google_Service_JobService_HistogramResults
[histogramResultsDataType:protected] =>
[jobView] =>
[matchingJobsType:protected] => Google_Service_JobService_MatchingJob
[matchingJobsDataType:protected] => array
[metadataType:protected] => Google_Service_JobService_ResponseMetadata
[metadataDataType:protected] =>
[nextPageToken] =>
[numJobsFromBroadenedQuery] => 0
[spellResultType:protected] => Google_Service_JobService_SpellingCorrection
[spellResultDataType:protected] =>
[totalSize] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
[metadata] => Google_Service_JobService_ResponseMetadata Object
(
[collection_key:protected] => experimentIdList
[experimentIdList] => Array
(
[0] => 11300310
[1] => 11300342
)
[mode] => JOB_SEARCH
[requestId] => f5cacd36-db29-4d65-851f-34a97c98af79:APAb7IRQAVop4QZ6rC2OlKjcEARRJQHI8w==
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
)
Array
(
)
我在这里感到困惑,Talent API 可以在我们的网站上搜索和加载谷歌工作或我们需要创建公司和工作,他们只提供使用 AI 和 ML 的高级搜索过滤器?
如果他们在我们的网站上提供谷歌工作,那么我的代码有什么问题?
请给我建议。
【问题讨论】:
标签: php google-api artificial-intelligence google-api-php-client