zoukankan      html  css  js  c++  java
  • Facebook SDK

    <?php
    session_start();
    header('Content-type:text/html; charset=UTF-8');
    
    require_once './facebook-php-sdk-v4-4.0-dev/autoload.php';
    
    use FacebookFacebookRequest;
    use FacebookGraphUser;
    use FacebookFacebookRequestException;
    use FacebookFacebookSession;
    use FacebookFacebookRedirectLoginHelper;
    
    FacebookSession::setDefaultApplication('3455677266264', 'nnvu8883332fvg550d40f8fcf8e6df2e2');
    
    // 回调获取session
    $helper = new FacebookRedirectLoginHelper('http://www.adtuu-server.com/facebook/callback.php');
    
    try {
        $session = $helper->getSessionFromRedirect();
    
    } catch(FacebookRequestException $ex) {
        // When Facebook returns an error
        echo '1:';
         var_dump($ex->getMessage());
    } catch(Exception $ex) {
        // When validation fails or other local issues
        echo '2:';
        var_dump($ex->getMessage());
    }
    
    
    if ($session) {
        // Logged in 这个token返回的 有效期节点没有值
         echo $access_token = $session->getToken();
    var_dump($session);
    
        /* ここで有効期限を延長させてます  60天token有效期*/
        $longSession = $session->getLongLivedSession();
        $accessToken = $longSession->getToken();
    
        echo '<br />' . $accessToken;
            var_dump($longSession);
    
    }
    exit;
    
    
    
    
    
    //https://developers.facebook.com/docs/graph-api/reference/v2.1/user
    
    //$access_token = 'as3s4de4vM3wqSmiSi7jP8ZBg1CPLvKxeJKUWszWV0cfZAoaHMk8CfqA6mjGXC5G1ZBfWCC7IQimExlujpWs1CwayjiAuqtPrZBQBevuyZB9ySEfZAUjMTC6SJsQD1pTp9MEaf8';
    $access_token = '2cjiktwxzjzpzP0gINsla10L4ZClsP5KhbCmsO0gf6VUSNPJYJHy7cOiYhwxqYZA0fDALEINcZBZBqGlKHZBXSdygYNUHCQskZC6DfkPmH0ivS6bqdTbdGwViFkiDHZCMw3evAWQ3BNINvMAgVaaWL1xvi2wqEVu70p90hIkt3xVgbbHnAnrfgPA7iCV7z5TXZCx5SKboWvd80JHdq';
    
    $session = new FacebookSession($access_token);
    try {
    
             $user_profile = (new FacebookRequest(
               $session, 'GET', '/me'
             ))->execute()->getGraphObject(GraphUser::className());
    
             echo "Name: " . $user_profile->getName();
    
        } catch(FacebookRequestException $e) {
    
             echo "Exception occured, code: " . $e->getCode();
             echo " with message: " . $e->getMessage();
    
        }  
    
    
    
    try {
         $friends = (new FacebookRequest(
               $session, 'GET', '/me/friendlists'
             ))->execute()->getGraphObject(GraphUser::className());
    var_dump($friends);
    } catch (Exception $e) {
    
         var_dump($e);
    }
    
    exit;
    
        try {
    
        $response = (new FacebookRequest(
          $session, 'POST', '/me/feed', array(
            'link' => 'http://www.adtuu.com',
            'message' => 'Hi, Adtuu !!!'
          )
        ))->execute()->getGraphObject();
    
        echo "Posted with id: " . $response->getProperty('id');
    
      } catch(FacebookRequestException $e) {
    
        echo "Exception occured, code: " . $e->getCode();
        echo " with message: " . $e->getMessage();
    
      }  
    
    
      try {
    
        // Upload to a user's profile. The photo will be in the
        // first album in the profile. You can also upload to
        // a specific album by using /ALBUM_ID as the path    
        $response = (new FacebookRequest(
          $session, 'POST', '/me/photos', array(
            'source' => new CURLFile('/Users/zhoutingze/webroot/facebook/post.jpg', 'image/jpeg'),
            'message' => 'User provided message'
          )
        ))->execute()->getGraphObject();
    
        // If you're not using PHP 5.5 or later, change the file reference to:
        // 'source' => '@/path/to/file.name'
    
        echo "Posted with id: " . $response->getProperty('id');
    
      } catch(FacebookRequestException $e) {
    
        echo "Exception occured, code: " . $e->getCode();
        echo " with message: " . $e->getMessage();
    
      }  
    
    
       try {
    
        $response = (new FacebookRequest(
          $session, 'POST', '/me/feed', array(
            'link' => 'http://www.baidu.com/img/bd_logo1.png',
            'message' => 'Hi, Adtuu !!!'
          )
        ))->execute()->getGraphObject();
    
        echo "Posted with id: " . $response->getProperty('id');
    
      } catch(FacebookRequestException $e) {
    
        echo "Exception occured, code: " . $e->getCode();
        echo " with message: " . $e->getMessage();
    
      }   
    

      

  • 相关阅读:
    AGC037F Counting of Subarrays
    AGC025F Addition and Andition
    CF506C Mr. Kitayuta vs. Bamboos
    AGC032D Rotation Sort
    ARC101F Robots and Exits
    AGC032E Modulo Pairing
    CF559E Gerald and Path
    CF685C Optimal Point
    聊聊Mysql索引和redis跳表
    什么是线程安全
  • 原文地址:https://www.cnblogs.com/adtuu/p/4688308.html
Copyright © 2011-2022 走看看