What I am trying to accomplish is: when I save a or update a post, I want to access the Untappd API, grab a link to an image, and update an ACF field with that link. I am attempting to use the acf/save_post hook to accomplish this.
Here is what I have so far:
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);
There exists an ACF field called untappd_brewery_id, which allows me to connect to the Untappd's API. I am using Pintlab's Untappd Class to connect to the API. This code breaks when trying to create a new instance of a the Pintlabs_Service_Untappd class. I have attempted to create a function that creates a new instance of the class and invoke it in this function, but that has not worked for me either. Is it possible to connect to an API when using the acf/save_post web hook?
Any help would be greatly appreciated. Thanks!