Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Copyright 2011 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
- require 'facebook.php';
- ini_set('display_errors','1');
- error_reporting (E_ALL);
- // Create our Application instance (replace this with your appId and secret).
- $facebook = new Facebook(array(
- 'appId' => '',
- 'secret' => '',
- ));
- // Get User ID
- $user = $facebook->getUser();
- // We may or may not have this data based on whether the user is logged in.
- //
- // If we have a $user id here, it means we know the user is logged into
- // Facebook, but we don't know if the access token is valid. An access
- // token is invalid if the user logged out of Facebook.
- // Login or logout url will be needed depending on current user state.
- if ($user)
- {
- $logoutUrl = $facebook->getLogoutUrl();
- }
- else
- {
- $loginUrl = $facebook->getLoginUrl(array('scope'=>
- 'user_about_me,
- user_activities,
- user_birthday,
- user_checkins,
- user_education_history,
- user_events,
- user_groups,
- user_hometown,
- user_interests,
- user_likes,
- user_location,
- user_notes,
- user_photos,
- user_questions,
- user_relationships,
- user_relationship_details,
- user_religion_politics,
- user_status,
- user_subscriptions,
- user_videos,
- user_website,
- user_work_history,
- email,
- read_friendlists,
- read_insights,
- read_mailbox,
- read_requests,
- read_stream,
- xmpp_login,
- ads_management,
- create_event,
- manage_friendlists,
- manage_notifications,
- user_online_presence,
- friends_online_presence,
- publish_checkins,
- publish_stream,
- rsvp_event
- '));
- }
- //-----------------------------------------------------
- function some_wtf() {
- $object_id = array(); //заполняем массив объектов c отметкой like
- $i=0;
- //$fql='SELECT user_id FROM like WHERE object_id=415946355119791';
- //$fql.='.$object_id[6].';
- foreach ($user_likes_data as $array1)
- {
- $object_id[$i]=$array1['id'];
- //$fql.='.$object_id[$i].';
- ++$i;
- }
- //узнаем всех пользователей, которым нравится те же объекты, что и мне
- $fql='SELECT user_id FROM like WHERE object_id=415946355119791';
- $param=array(
- 'method' => 'fql.query',
- 'query' => $fql,
- 'callback' => ''
- );
- $fql_result1= $facebook->api($param);
- echo '<pre>';
- print_r($fql_result1);
- echo '</pre>';
- }
- //-----------------------------------------------------
- function collectInfo() {
- global $facebook;
- global $user;
- if ($user)
- {
- try
- {
- // Proceed knowing you have a logged in user who's authenticated.
- ob_start();
- $user_profile = $facebook->api('/me','GET'); //получаем информацию о профиле пользователя
- //$friends = $facebook->api('/me/friends'); // получаем список друзей текущего пользователя
- $user_likes = $facebook->api('/me/likes');
- echo 'user likes<br/>';
- echo '<pre>'.print_r($user_likes,true).'</pre>';
- $inf = ob_get_contents();
- ob_end_clean();
- return $inf;
- } catch (FacebookApiException $e)
- {
- return false;
- }
- }
- else
- return false;
- }
- //-----------------------------------------------------
- ?>
- <!doctype html>
- <html xmlns:fb="http://www.facebook.com/2008/fbml">
- <head>
- <title>php-sdk</title>
- <style>
- body {
- font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
- }
- h1 a {
- text-decoration: none;
- color: #3b5998;
- }
- h1 a:hover {
- text-decoration: underline;
- }
- </style>
- </head>
- <body>
- <h1>php-sdk</h1>
- <?php if ($user): ?>
- <a href="<?php echo $logoutUrl; ?>">Logout</a>
- <?php else: ?>
- <div>
- Login using OAuth 2.0 handled by the PHP SDK:
- <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
- </div>
- <?php endif ?>
- <?php
- $cdir = opendir('');
- while($inf=readdir($cdir)) {
- if (substr($inf,0,5)=='uinfo') {
- echo "<a href=\"$inf\" target=\"_blank\">$inf</a><br/>";
- }
- }
- closedir($cdir);
- $rez = collect_info();
- if ($rez!==false) {
- $fname='uinfo_'.date('d_m_Y_H_i_s').rand(6,8000).'.html';
- $fh = fopen($fname,'w');
- fwrite($fh, $rez);
- fclose($fh);
- echo "<h3>You</h3><img src=\"https://graph.facebook.com/$user/picture\" /><br/>";
- echo "user information collected in: <a href=\"$fname\" target=\"_blank\">$fname</a><br/>";
- }
- ?>
- <h3>PHP Session</h3>
- <pre><?php print_r($_SESSION); ?></pre>
- </body>
- </html>
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
- <?php
- $s='https://graph.facebook.com/zefirmedia/feed?access_token=AAAAAAITEghMBAA57e5imZBkZAZCEgooOgL4qkBOokGkFvfsBbUZADHe7YXzO7MxZCYWlVY3SKEZBUEVKHgGWHuGUA23yu3HSGREkyDMQByZAQs4czhBWV6ZB';
- /*$inf = file_get_contents($s);
- echo $inf;
- $fh = fopen('fb.txt','w');
- fwrite($fh, $inf);
- fclose($fh);*/
- $z = file_get_contents('fb.txt');
- $u=json_decode ($z);
- function _mks($s) {
- return iconv( 'utf-8','windows-1251', $s);
- }
- //echo '<pre>'.print_r($u).'</pre>';
- //-------------------------------------------------------
- $ff = <<<INF
- <style type="text/css">
- .zzui_block {
- width:330px;
- background-color:white;
- margin:10px 0 0 0;
- font-family:'lucida grande', tahoma, verdana, arial, sans-serif;
- font-size:80%;
- padding: 5px;
- height:300px;
- overflow:hidden;
- }
- .zzui_info {
- font-size:90%;
- border: solid 1px #aaa;
- width: 290px;
- padding:10px;
- margin: 10px;
- height:180px;
- overflow:hidden;
- }
- .zzui_ref {
- text-decoration: none;
- color:inherit;
- }
- .zzui_name {
- font-size:100%;
- color:#555;
- margin-left:100px;
- }
- .zzui_caption {
- color:#777;
- margin: 5px auto;
- float:left;
- width:100%;
- }
- .zzui_desc {
- }
- .zzui_pic {
- float:left;
- margin-right:10px;
- }
- </style>
- INF;
- echo $ff;
- foreach ($u->data as $inf) {
- //------------------------
- echo '<div class="zzui_block">';
- if (@$inf->message) {
- $m = $inf->message;
- $m = _mks($m);
- $m = preg_replace('/(https?:\/\/[^\s]+(\s|$))/ims', '<a href="\1" target="_blank">\1</a>',$m);
- echo "<div class=\"zzui_mes\">$m</div>";
- }
- //------------------------
- if (@$inf->name) {
- $link = $inf->link;
- $name = @_mks($inf->name);
- $caption = @_mks($inf->caption?$inf->caption:"");
- $description = @_mks(($inf->description)?$inf->description:"");
- $picture = @($inf->picture)?($inf->picture):"";
- $ss = <<<INF
- <a href="$link" class="zzui_ref" target="_blank">
- <div class="zzui_info">
- <div class="zzui_pic"><img src="$picture" /></div>
- <h1 class="zzui_name">$name</h1>
- <div class="zzui_caption">$caption</div>
- <div class="zzui_desc">$description</div>
- </div>
- </a>
- INF;
- echo $ss;
- } else {
- if (@$inf->picture) {
- $m = $inf->picture;
- $link = $inf->link;
- $ss = <<<INF
- <a href="$link" target="_blank">
- <img src="$m"/>
- </a>
- INF;
- echo $ss;
- }}
- //-----------------------
- echo '</div>';
- }
- ?>
- //---------------------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------------------
- <?php
- //-------------------------------------
- function fill_db($db, $arr) {
- $sqls = array (sprintf('insert into fb_me
- (fb_id, fb_name, fb_first_name,
- fb_last_name, fb_link, fb_username,
- fb_birthday, fb_location_id,
- fb_location_name, fb_gender, fb_email)
- values(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',
- \'%s\',\'%s\',\'%s\',\'%s\') ',
- sqlite_escape_string($arr["me"]["id"]),
- sqlite_escape_string($arr["me"]["name"]),
- sqlite_escape_string($arr["me"]["first_name"]),
- sqlite_escape_string($arr["me"]["last_name"]),
- sqlite_escape_string($arr["me"]["link"]),
- sqlite_escape_string($arr["me"]["username"]),
- sqlite_escape_string($arr["me"]["birthday"]),
- sqlite_escape_string($arr["me"]["location"]["id"]),
- sqlite_escape_string($arr["me"]["location"]["name"]),
- sqlite_escape_string($arr["me"]["gender"]),
- sqlite_escape_string($arr["me"]["email"])
- )
- );
- for ($i=0; $i<count($sqls); $i++) {
- if (!$db->query($sqls[$i]))
- echo sqlite_error_string($db->lastError()).'<br/>';
- else {
- $r_id = $db->lastInsertRowid();
- echo 'record inserted with rowid:'.$r_id;
- }
- }
- };
- //-------------------------------------
- function cr_db() {
- $sqls = array (
- ' DROP TABLE fb_me',
- ' CREATE TABLE fb_me(
- fb_id int,
- fb_name varchar(100),
- fb_first_name varchar(100),
- fb_last_name varchar(100),
- fb_link varchar(300),
- fb_username varchar(100),
- fb_birthday varchar(30),
- fb_location_id int,
- fb_location_name varchar(100),
- fb_gender varchar(30),
- fb_email varchar(100))');
- if ($db = new SQLiteDatabase('testfbdb.dat')) {
- //refl_check($db);
- for ($i=0; $i<count($sqls); $i++) {
- if (!$db->query($sqls[$i])) {
- echo (sqlite_error_string($db->lastError())).'<br/>';
- }
- }
- } else {
- throw new Exception('error opening database');
- }
- return $db;
- }
- //-----------------------------------------
- function myHandler($e) {
- echo '<br/><b>Uncaught exception: '.$e->getMessage().'</b><br/>';
- }
- //-----------------------------------------
- function myErrorHandler($errno, $errstr, $errfile, $errline) {
- switch ($errno) {
- case E_ERROR: echo '<br/>Error:<br/>'.$errstr."<br/>Line:$errline<br/>";
- break;
- case E_WARNING: echo '<br/>Warning:<br/>'.$errstr."<br/>Line:$errline<br/>";
- break;
- case E_NOTICE: echo '<br/>Notice:<br/>'.$errstr.'<br/>Line:'.$errline.'<br/>';
- break;
- default: echo "<br/>errno:$errno<br/>errstr:$errstr<br/>errline:$errline<br/>";
- }
- return true;
- }
- //-----------------------------------------
- set_exception_handler('myHandler');
- $old_error_handler=set_error_handler('myErrorHandler');
- define('INFF',
- 'http://socium.unisample.com/logs/uinfo_kitsunesama.zinfo_11_10_2012_09_19_53_5293.txt');
- //-------------------------------------
- function refl_check($obj) {
- $clname = get_class($obj);
- echo $clname;
- $mt = get_class_methods($clname);
- //-------------------------
- echo '<pre>';
- var_dump($mt);
- echo '</pre>';
- //-------------------------
- $cl_v = get_class_vars($clname);
- //-------------------------
- echo '<pre>';
- var_dump($cl_v);
- echo '</pre>';
- echo str_repeat('-',40).'<br/>';
- echo 'Reflections<br/>';
- echo str_repeat('-',40).'<br/>';
- $rfl = new ReflectionClass($clname);
- $mth = $rfl->getMethods();
- echo '<pre>'.var_export($mth, true).'</pre>';
- $prp = $rfl->getProperties();
- echo '<pre>'.var_export($prp, true).'</pre>';
- $cnt = $rfl->getConstants();
- echo '<pre>'.var_export($cnt, true).'</pre>';
- }
- //-------------------------------------
- $s = file_get_contents(INFF);
- $arr = array();
- $arr= unserialize($s);
- //header('content-type: text/html; charset=utf-8');
- //echo '<pre>'.print_r($arr, true).'</pre>';
- //echo '<pre>'.var_export($arr, true).'</pre>';
- $db = cr_db();
- fill_db($db, $arr);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement