因此,我尝试在Wordpress中操作functions.php文件,添加一个函数,该函数将使用API2.0或OAUth密钥(以更安全的为准)调用Google Sheets API,获取列中的元素列表并将其存储在一个数组$options中,然后该数组将显示为下拉菜单列表。
为了用忍者表单选择字段预填充,我引用了$options是一个数组,当静态设置时,它会给出预期的下拉菜单:例如-
$options[1]['label'] = "One";
$options[2]['label'] = "Two";
$options[3]['label'] = "Three"; 我尝试过https://developers.google.com/sheets/api/quickstart/php的OAuth 2.0方法
在$client->setAuthConfig( '/credentials.json' );行中,代码不能访问文件credentials.json。我确实在与functions.php相同的文件夹中添加了JSON文件和所有其他相关的API文件。此外,我还需要一种方法来自动化
我希望元素列表显示在Wordpress的下拉列表中。相反,我在debug.log文件中得到了一个空白页面和下面的堆栈跟踪:
[09-Jul-2019 19:46:15 UTC] PHP Fatal error: Uncaught InvalidArgumentException: file "/credentials.json" does not exist in /var/www/html/wp-content/themes/twentynineteen/vendor/google/apiclient/src/Google/Client.php:870
#0 /var/www/html/wp-content/themes/twentynineteen/functions.php(322):
Google_Client->setAuthConfig('/credentials.js...')
#1 /var/www/html/wp-content/themes/twentynineteen/functions.php(371): getClient()
#2 /var/www/html/wp-content/themes/twentynineteen/functions.php(437): quickstart()
#3 /var/www/html/wp-includes/class-wp-hook.php(286): select_pre_population_callback(Array, Array)
#4 /var/www/html/wp-includes/plugin.php(208): WP_Hook->apply_filters(Array, Array)
#5 /var/www/html/wp-content/plugins/ninja-forms/includes/Display/Render.php(271): apply_filters('ninja_forms_ren...', Array, Array)
#6 /var/www/html/wp-content/plugins/ninja-forms/includes/Display/Render.php(400): NF_Display_Render::localize(1)
#7 /var/www/html/wp-content/plugins/ninja-forms/ninja-forms.php(935): NF_Display_Render::localize_preview('1')
#8 /var/www/h in /var/www/html/wp-content/themes/twentynineteen/vendor/google/apiclient/src/Google/Client.php on line 870发布于 2019-07-19 03:20:36
@cabrerahector的评论对我很有效。
PHP告诉我们它找不到credentials.json文件。而是尝试这样做:$client->setAuthConfig( get_theme_file_path('credentials.json') )
https://stackoverflow.com/questions/56959418
复制相似问题