Created
February 16, 2012 00:53
-
-
Save ha1t/1840397 to your computer and use it in GitHub Desktop.
facebookでtestuser作ったり一覧だすクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* @url http://blog.maripo.org/2011/05/facebook-%E3%82%A2%E3%83%97%E3%83%AA%E3%81%A4%E3%81%8F%E3%82%8D%E3%81%86%E3%81%9C-%E3%81%9D%E3%81%AE8-%E3%83%86%E3%82%B9%E3%83%88%E3%83%A6%E3%83%BC%E3%82%B6%E3%82%92%E4%BD%9C%E3%82%89%E3%81%AA/ | |
* @url http://developers.facebook.com/docs/test_users/ | |
*/ | |
$APP_ID = ''; | |
$APP_SECRET = ''; | |
$SITE_URL = ''; | |
class FacebookManager | |
{ | |
private $APP_ID; | |
private $APP_SECRET; | |
private $SITE_URL; | |
private $access_token; | |
public function __construct($APP_ID, $APP_SECRET, $SITE_URL) | |
{ | |
$this->APP_ID = $APP_ID; | |
$this->APP_SECRET = $APP_SECRET; | |
$this->SITE_URL = $SITE_URL; | |
$this->access_token = $this->getAccessToken(); | |
} | |
private function getAccessToken() | |
{ | |
$url = "https://graph.facebook.com/oauth/access_token?client_id={$this->APP_ID}&client_secret={$this->APP_SECRET}&redirect_uri={$this->SITE_URL}&grant_type=client_credentials"; | |
$result = file_get_contents($url); | |
list($no_use, $access_token) = explode('=', $result); | |
return $access_token; | |
} | |
public function createTestUser() | |
{ | |
$permissions = 'offline_access'; // 生成時に必要なPermissionsをカンマ区切りで | |
$installed = 'true'; // インストール済状態のユーザを作るならtrue, そうでなければfalse | |
$url = "https://graph.facebook.com/{$this->APP_ID}/accounts/test-users?installed={$installed}&permissions={$permissions}&method=post&access_token={$this->access_token}"; | |
$result_json = file_get_contents($url); | |
return json_decode($result_json, true); | |
} | |
public function getTestUserList() | |
{ | |
$url = "https://graph.facebook.com/{$this->APP_ID}/accounts/test-users?access_token={$this->access_token}"; | |
$result_json = file_get_contents($url); | |
return json_decode($result_json, true); | |
} | |
} | |
$fm = new FacebookManager($APP_ID, $APP_SECRET, $SITE_URL); | |
// テストユーザーつくる | |
var_dump($fm->createTestUser()); | |
// そのアプリケーションで作られたテストアカウントの一覧 | |
// var_dump($fm->getTestUserList()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment