/** * Send a request to Graph with an app access token. * * @param string $endpoint * @param array $params * @param string|null $accessToken * * @return FacebookResponse * * @throws FacebookResponseException */ protected function sendRequestWithClientParams($endpoint, array $params, $accessToken = null) { $params += $this->getClientParams(); $accessToken = $accessToken ?: $this->app->getAccessToken(); $this->lastRequest = new FacebookRequest($this->app, $accessToken, 'GET', $endpoint, $params, null, $this->graphVersion); return $this->client->sendRequest($this->lastRequest); }
/** * @group integration */ public function testCanCreateATestUserAndGetTheProfileAndThenDeleteTheTestUser() { $this->initializeTestApp(); // Create a test user $testUserPath = '/' . FacebookTestCredentials::$appId . '/accounts/test-users'; $params = ['installed' => true, 'name' => 'Foo Phpunit User', 'locale' => 'en_US', 'permissions' => implode(',', ['read_stream', 'user_photos'])]; $request = new FacebookRequest(static::$testFacebookApp, static::$testFacebookApp->getAccessToken(), 'POST', $testUserPath, $params); $response = static::$testFacebookClient->sendRequest($request)->getGraphObject(); $testUserId = $response->getProperty('id'); $testUserAccessToken = $response->getProperty('access_token'); // Get the test user's profile $request = new FacebookRequest(static::$testFacebookApp, $testUserAccessToken, 'GET', '/me'); $graphObject = static::$testFacebookClient->sendRequest($request)->getGraphObject(); $this->assertInstanceOf('Facebook\\GraphNodes\\GraphObject', $graphObject); $this->assertNotNull($graphObject->getProperty('id')); $this->assertEquals('Foo Phpunit User', $graphObject->getProperty('name')); // Delete test user $request = new FacebookRequest(static::$testFacebookApp, static::$testFacebookApp->getAccessToken(), 'DELETE', '/' . $testUserId); $graphObject = static::$testFacebookClient->sendRequest($request)->getGraphObject(); $this->assertTrue($graphObject->getProperty('success')); }
/** * Get more info about an access token. * * @param FacebookApp $app The FacebookApp entity. * @param FacebookClient $client The Facebook client. * * @return GraphSessionInfo */ public function getInfo(FacebookApp $app, FacebookClient $client) { $params = ['input_token' => $this->accessToken]; $request = new FacebookRequest($app, $app->getAccessToken(), 'GET', '/debug_token', $params); $response = $client->sendRequest($request); $graphObject = $response->getGraphSessionInfo(); // Update the data on this token if ($graphObject->getExpiresAt()) { $this->expiresAt = $graphObject->getExpiresAt(); } return $graphObject; }