Commit 97ce5005 authored by Isaque Melo's avatar Isaque Melo

Fix API problems

parent 5b01225e
......@@ -9,23 +9,24 @@ function get_facebook_shares( $data ) {
}
// example
// $access_token = '1855140564616229|32c79e113db5a2911aeed2c4ca330b3f';
// $access_token = '693244528146031|ae2b14c2d4f31b3434212179ee5550d8';
$access_token = get_option( 'fb_app_id' ). '|' . get_option( 'fb_app_secret' );
$post_id = $data['post_id'];
if( guaraci\need_share_update( $post_id ) ) {
if( guaraci\need_share_update( $post_id ) || true ) {
$response = wp_remote_get( add_query_arg( array(
'id' => urlencode( get_permalink( $post_id ) ),
//'id' => urlencode( 'https://www.google.com/' ),
//'id' => urlencode( get_permalink( $post_id ) ),
'id' => urlencode( 'https://www.google.com/' ),
'access_token' => $access_token,
'fields' => 'engagement'
), 'https://graph.facebook.com/v3.0/' ) );
if ( !is_array($response) && is_wp_error( $response ) ) {
return false;
}
if ( !is_array($response) || is_wp_error( $response ) || $response['response']['code'] != 200){
return guaraci\get_post_shares( $post_id );
}
$body = json_decode( $response['body'] );
$count = intval( $body->engagement->share_count );
......
......@@ -3,7 +3,6 @@
namespace guaraci;
function need_share_update( $post_id ) {
// se o metadado não existe ou se o metadado existe e foi atualizado a mais tempo do que o intervalo (F), retorna true
if ( !metadata_exists( 'post', $post_id, 'shares' ) ) {
// the first time its called create the metadata for the next turn
update_post_meta( $post_id, 'shares', 0 );
......@@ -33,7 +32,7 @@ function update_share_business_rule( $post_id ) {
$time_interval = $date_obj->diff(new \DateTime('NOW'));
$hours_passed = ($time_interval->days * 24) + $time_interval->h;
var_dump($rank_position);
//var_dump($rank_position);
if ( $rank_position >= 1 && $rank_position < 100 && $hours_passed >= 1){
return true;
......@@ -55,5 +54,5 @@ function set_post_shares( $post_id, $shares ) {
}
function get_post_shares( $post_id ) {
get_post_meta( $post_id, 'shares', true);
return get_post_meta( $post_id, 'shares', true);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment