Ejemplo n.º 1
0
            // Unable to get access token. We'll settle for a request token instead.
            $request = $twitter->getRequestToken();
            if ($request) {
                $_SESSION['request'] = serialize($request);
                // Display or redirect to user to their login URL.
                echo '<a href="' . $twitter->getLoginURL() . '">' . $twitter->getLoginURL() . '</a>';
            } else {
                // Problems.
                echo 'Unable to get request token.';
            }
        }
    }
} else {
    // The user has authorized access to the application.
    // Get the current user.
    $user = $twitter->getUser();
    /**
     * The above call is the same as doing the following:
     *
     * $result = $twitter->api("1.1/account/verify_credentials.json");
     * if($result->statusCode() == 200)
     *      $user = json_decode($result->body(), true);
     * else
     *      $user = false;
     **/
    if ($user) {
        echo "Hello, " . $user['screen_name'] . "<br />" . "<a href=\"?reset=1\">Log out</a>";
    } else {
        echo "Unable to fetch the users' data.";
    }
}
 function syncFriends()
 {
     $mt = new microAccountsTable($this->db);
     $ma = $mt->getRowObject();
     // get list of friends
     require_once PATH_CORE . '/utilities/twitter.php';
     $tObj = new Twitter(TWITTER_USER, TWITTER_PWD, $this->db);
     $friends = $tObj->getFriendIds(TWITTER_USER);
     foreach ($friends as $id) {
         // get info for anyone not in the table
         $resp = $tObj->getUser($id);
         if ($resp !== false) {
             //			$this->db->log($resp);
             // check if they exist
             $ma->sid = $resp['id'];
             $ma->friendlyName = $resp['name'];
             $ma->profile_image_url = $resp['profile_image_url'];
             $q = $this->db->queryC("SELECT * FROM MicroAccounts WHERE sid=" . $ma->sid);
             if (!$q) {
                 // does not exist, add them
                 $ma->shortName = $resp['screen_name'];
                 $ma->tag = 'default';
                 $ma->service = 'twitter';
                 $ma->insert();
             } else {
                 $ma->update();
             }
         } else {
             //			$this->db->log('FALSE');
         }
     }
     // delete anyone no longer listed - set status - friends vs. not friends
 }