我试图做到的是:当我保存或更新帖子时,我想访问Untappd API,获取到图像的链接,并用该链接更新ACF字段。我正在尝试使用acf/save\\U post挂钩来完成此操作。
以下是我目前掌握的情况:
function brewImageUpdater( $post_id ){
require_once \'Pintlabs/Service/Untappd.php\';
$config = array(
\'clientId\' => \'XXXXXX\',
\'clientSecret\' => \'XXXXXX\',
\'redirectUri\' => \'stuff.com\',
\'accessToken\' => \'\'
);
$untappdd = new Pintlabs_Service_Untappd($config);
$brid = get_field(\'untappd_brewery_id\', $post_id);
$brid= int($brid);
try {
$feed = $untappd->breweryInfo($brid);
}
catch (Exception $e) {
echo \'Unable to connect to the Untappd API<br />\';
}
$bi = $feed->response->brewery->brewery_label;
$fkey = "field_5609f19dcec5d";
update_field($fkey, $bi, $post_id);
}
add_action( \'acf/save_post\', \'brewImageUpdater\', 20);
存在一个名为untappd\\u brewery\\u id的ACF字段,允许我连接到untappd的API。我正在使用
Pintlab\'s Untappd Class to connect to the API. 尝试创建Pintlabs\\u Service\\u Untappd类的新实例时,此代码中断。我试图创建一个函数来创建该类的新实例并在此函数中调用它,但这对我也不起作用。使用acf/save\\u post web挂钩时是否可以连接到API?
任何帮助都将不胜感激。谢谢