function _ping() { $response = asg_remote_get(add_query_arg('access_token', $_REQUEST['data']['access_token'], 'https://api.instagram.com/v1/users/self/feed')); if ($response['response']['code'] == 200) { echo 'OK'; } else { echo 'FAIL'; } exit; }
function _auth_show() { $state = stripslashes($_REQUEST['state']); list($app_id, $app_secret) = explode('|', $state); $redirect_url = admin_url('admin.php?action=asg-facebook-auth-show'); $response = asg_remote_get("https://graph.facebook.com/oauth/access_token?client_id={$app_id}&redirect_uri={$redirect_url}&client_secret={$app_secret}&code=" . stripslashes($_REQUEST['code'])); if (is_wp_error($response)) { var_dump($response); exit; } if ($response['response']['code'] == 400) { echo "Token expired. Please re-copy the URL and try again."; } else { $data = wp_parse_args($response['body']); ?> <!doctype html> <html> <body> <strong>Please copy the next parameters:</strong><br> <br> <strong>ACCESS TOKEN: </strong><?php echo $data['access_token']; ?> <br> <strong>EXPIRES: </strong><?php echo $data['expires']; ?> <br> <?php $user_data = wp_remote_get('https://graph.facebook.com/v2.0/me?access_token=' . $data['access_token']); ?> <?php $user_data = json_decode($user_data['body'], true); ?> <strong>USER / PAGE ID: </strong><?php echo $user_data['id']; ?> </body><?php } }
function http_get_cached($url, $options = array()) { $response = asg_remote_get($url, $options); if (is_wp_error($response)) { return $response; } if ($response['response']['code'] != 200 && $response['response']['code'] != 206) { return new WP_Error($response['response']['code'], $response['body']); } return $response['body']; }