Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Support Gaming Graph Domain #1261

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Facebook/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function __construct(array $config = [])
'app_secret' => getenv(static::APP_SECRET_ENV_NAME),
'default_graph_version' => static::DEFAULT_GRAPH_VERSION,
'enable_beta_mode' => false,
'use_gaming_graph' => false,
'http_client_handler' => null,
'persistent_data_handler' => null,
'pseudo_random_string_generator' => null,
Expand All @@ -145,7 +146,8 @@ public function __construct(array $config = [])
$this->app = new FacebookApp($config['app_id'], $config['app_secret']);
$this->client = new FacebookClient(
HttpClientsFactory::createHttpClient($config['http_client_handler']),
$config['enable_beta_mode']
$config['enable_beta_mode'],
$config['use_gaming_graph']
);
$this->pseudoRandomStringGenerator = PseudoRandomStringGeneratorFactory::createPseudoRandomStringGenerator(
$config['pseudo_random_string_generator']
Expand Down
17 changes: 16 additions & 1 deletion src/Facebook/FacebookClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class FacebookClient
*/
const BASE_GRAPH_VIDEO_URL_BETA = 'https://graph-video.beta.facebook.com';

/**
* @const string Gaming Graph API URL.
*/
const GAMING_GRAPH_URL = 'https://graph.fb.gg';

/**
* @const int The timeout in seconds for a normal request.
*/
Expand All @@ -75,6 +80,11 @@ class FacebookClient
*/
protected $enableBetaMode = false;

/**
* @var bool Toggle to use Gaming Graph url.
*/
protected $useGamingGraph = false;

/**
* @var FacebookHttpClientInterface HTTP client handler.
*/
Expand All @@ -91,10 +101,11 @@ class FacebookClient
* @param FacebookHttpClientInterface|null $httpClientHandler
* @param boolean $enableBeta
*/
public function __construct(FacebookHttpClientInterface $httpClientHandler = null, $enableBeta = false)
public function __construct(FacebookHttpClientInterface $httpClientHandler = null, $enableBeta = false, $useGamingGraph = false)
{
$this->httpClientHandler = $httpClientHandler ?: $this->detectHttpClientHandler();
$this->enableBetaMode = $enableBeta;
$this->useGamingGraph = $useGamingGraph;
}

/**
Expand Down Expand Up @@ -150,6 +161,10 @@ public function getBaseGraphUrl($postToVideoUrl = false)
return $this->enableBetaMode ? static::BASE_GRAPH_VIDEO_URL_BETA : static::BASE_GRAPH_VIDEO_URL;
}

if ($this->useGamingGraph) {
return static::GAMING_GRAPH_URL;
}

return $this->enableBetaMode ? static::BASE_GRAPH_URL_BETA : static::BASE_GRAPH_URL;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/FacebookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,24 @@ public function testMaxingOutRetriesWillThrow()
$fb = new Facebook($config);
$fb->uploadVideo('4', __DIR__.'/foo.txt', [], 'foo-token', 3);
}

public function testCreatingANewRequestWithGamingGraphDomain()
{
$config = array_merge($this->config, [
'app_id' => FacebookTestCredentials::$appId,
'app_secret' => FacebookTestCredentials::$appSecret,
'use_gaming_graph' => true,
]);
$fb = new Facebook($config);

$oauth = $fb->getOAuth2Client();
$metadata = $oauth->debugToken('baz_token');

$this->assertInstanceOf('Facebook\Authentication\AccessTokenMetadata', $metadata);

$request = $oauth->getLastRequest();
$this->assertEquals('GET', $request->getMethod());
$this->assertEquals('/debug_token', $request->getEndpoint());
$this->assertEquals(Facebook::DEFAULT_GRAPH_VERSION, $request->getGraphVersion());
}
}