2012年10月25日木曜日

cakephp2 hybridauth(2)

hybridauth概要 その2/2です。

Hybrid_User_Profile Name type description
  identifier String  
Properties profileURL String IDPのWebサイト上でプロフィールページへのURLリンク
  webSiteURL String  
  photoURL String ユーザー写真やアバターへのURLリンク
  displayName String  
  description String 短いabout_me
  firstName String  
  lastName String  
  gender String  
  language String  
  age Integer  
  birthDay Integer  
  birthMonth Integer  
  birthYear Integer  
  email String  
  emailVerified String  
  phone String  
  address String  
  country String  
  region String  
  city String  
  zip Integer  
Update User Status      $hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "Facebook" );
$adapter->setUserStatus(
    array(
       "message" => "", // status or message content
       "link" => "", // webpage link
       "picture" => "", // a picture link
       )
    ); 
      $hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "Twitter" );
$adapter->setUserStatus( "Hi there!" ); 
Hybrid_User_Contact $hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "Twitter" );
$user_contacts = $adapter->getUserContacts();
foreach( $user_contacts as $contact ){
     echo $contact->displayName . " " . $contact->profileURL . "<hr />";
}
  Field Name Type Short description
  identifier  String The Unique contact's ID on the connected provider. Usually an interger.
  profileURL  String URL link to profile page on the IDp web site
  webSiteURL  String ユーザのウェブサイト、ブログ、ウェブページ
  photoURL  String ユーザー写真やアバターへのURLリンク
  displayName  String User dispalyName provided by the IDp or a concatenation of first and last name.
  description  String 短いabout_meまたは最後の接触状況
  email  String User email. Not all of IDp garant access to the user email
Hybrid_User_Activity $hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "Twitter" );
$user_timeline = $adapter->getUserActivity( "timeline" );
foreach( $user_timeline as $item ){
    echo $item->user->displayName . ": " . $item->text . "<hr />";
}

$user_timeline = $adapter->getUserActivity( "me" );
foreach( $user_timeline as $item ){
    echo $item->user->displayName . ": " . $item->text . "<hr />";
}
  Field Name Type Short description
  id  String Event id on the provider side
  date  String Event date of creation. provided as is for now.
  text  String activity/event/story content as string.
  user  stdClass Field Name    Type    Short description
------------------------------------------------------
identifier        string   The Unique user ID on the provider side. Usually an interger.
displayName string   User dispalyName provided by the provider
profileURL     string   URL link to profile page on the IDp web site
photoURL      string   URL link to user photo or avatar
Access social networks apis     try{
    $hybridauth = new Hybrid_Auth( $config );
    $facebook = $hybridauth->authenticate( "Facebook" );
    $twitter = $hybridauth->authenticate( "Twitter" );

    /* Facebook: https://developers.facebook.com/docs/reference/api/  */
    $response = $facebook->api()->api('/me/friends');
    $response = $facebook->api()->api("/me/feed", "post", array(
        message => "Hi there",
        picture => "http://www.mywebsite.com/path/to/an/image.jpg",
        link => "http://www.mywebsite.com/path/to/a/page/",
        name => "My page name",
       caption => "And caption"
       ));

     /* Twitter: https://dev.twitter.com/docs/api */
    $response = $twitter->api()->get( 'account/totals.json' );
   }
catch( Exception $e ){
    echo "Ooophs, we got an error: " . $e->getMessage();
}
HybridAuth Sessions         CREATE TABLE `users_connections` (
    `user_id` int(11) NOT NULL COMMENT 'refer to your user id on your application',
    `hybridauth_session` text NOT NULL COMMENT 'will contain the hybridauth session data',
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    ) ENGINE=InnoDB;
      try{
$hybridauth = new Hybrid_Auth( $config );
$twitter = $hybridauth->authenticate( "Twitter" );
$facebook = $hybridauth->authenticate( "Facebook" );
$google = $hybridauth->authenticate( "Google" );
/* ... */

$hybridauth_session_data = $hybridauth->getSessionData();
 
// then store it on your database or something
sotre_hybridauth_session( $current_user_id, $hybridauth_session_data );
}
catch( Exception $e ){
    echo "Ooophs, we got an error: " . $e->getMessage();
}
 
// define a function to sotre it on whatever storage you want to use
function sotre_hybridauth_session( $user_id, $data ){
    $sql = "INSERT INTO users_connections ( user_id, hybridauth_session ) VALUES (  $user_id , $data )";
// ..
}
      try{
    $hybridauth = new Hybrid_Auth( $config );

    $hybridauth_session_data = get_sotred_hybridauth_session( $current_user_id );
    $hybridauth->restoreSessionData( $hybridauth_session_data );

   $twitter = $hybridauth->getAdapter( "Twitter" );

  $user_profile = $twitter->getUserProfile();
 
// ..
}
catch( Exception $e ){
   echo "Ooophs, we got an error: " . $e->getMessage();
}
 
// define a function to get the stored hybridauth data back from your storage system
function get_sotred_hybridauth_session( $user_id ){
    $sql = "SELECT FROM users_connections WHERE user_id = $user_id ";
    return ...
}

0 件のコメント:

コメントを投稿