Esempio n. 1
0
<?php

require_once 'inc/db.php';
require_once 'inc/helper.php';
require_once 'inc/fetch.php';
$fetchFacebook = true;
$saveToDB = true;
echo 'Start fetch Facebook: ' . date("Y-m-d H:i:s") . '<br>';
foreach ($accounts as $account) {
    echo 'Get stat for: ' . $account['url'] . ' - ' . date("Y-m-d H:i:s") . '<br>';
    //get facebook page stat
    if ($fetchFacebook && $account['fb_pageid'] != '') {
        facebookLogin($account['ga_username'], $account['ga_passwd']);
        $ch = getCURLResource();
        curl_setopt($ch, CURLOPT_URL, "http://www.facebook.com/business/insights/json.php?id=" . $account['fb_pageid'] . "&reports=1");
        $buf2 = curl_exec($ch);
        curl_close($ch);
        //$tempArr = explode('or (;;);',$buf2);
        //$tempArr = json_decode($tempArr[1], true);
        //echo '<pre>'.$buf2.'</pre>';
        $result = array();
        $tempArr = explode('{"Total Interactions":[[', $buf2);
        $tempArr = explode(']]},{"Comments"', $tempArr[1]);
        $tempArr = explode('],[', $tempArr[0]);
        for ($i = 0; $i < sizeof($tempArr); $i++) {
            $tempArr[$i] = explode(',', $tempArr[$i]);
        }
        $result['Total Interactions'] = $tempArr;
        $tempArr = explode('{"Comments":[[', $buf2);
        $tempArr = explode(']]},{"Wall Posts"', $tempArr[1]);
        $tempArr = explode('],[', $tempArr[0]);
Esempio n. 2
0
require_once 'includes/config.php';
require DIR_LIBS . 'Facebook_Twitter/facebook/facebook.php';
require DIR_LIBS . 'Facebook_Twitter/config/fbconfig.php';
require_once DIR_APP . 'users.php';
$facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_SECRET));
$user = $facebook->getUser();
if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
    if (!empty($user_profile)) {
        # User info ok? Let's print it (Here we will be adding the login and registering routines)
        $username = $user_profile['name'];
        $uid = $user_profile['id'];
        $email = $user_profile['email'];
        $userdata = facebookLogin($uid, 'facebook', $username, $email);
        sleep(5);
        redirect('index.php');
    } else {
        # For testing purposes, if there was an error, let's kill the script
        die("There was an error.");
    }
} else {
    # There's no active session, let's generate one
    $login_url = $facebook->getLoginUrl(array('scope' => 'email'));
    header("Location: " . $login_url);
}