OAuthOAuth2ServiceDailymotion

Dailymotion service.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Dailymotion.php  
  1. class Dailymotion extends AbstractService 
  2. /** 
  3. * Scopes 
  4. * @var string 
  5. */ 
  6. const SCOPE_EMAIL = 'email',  
  7. SCOPE_PROFILE = 'userinfo',  
  8. SCOPE_VIDEOS = 'manage_videos',  
  9. SCOPE_COMMENTS = 'manage_comments',  
  10. SCOPE_PLAYLIST = 'manage_playlists',  
  11. SCOPE_TILES = 'manage_tiles',  
  12. SCOPE_SUBSCRIPTIONS = 'manage_subscriptions',  
  13. SCOPE_FRIENDS = 'manage_friends',  
  14. SCOPE_FAVORITES = 'manage_favorites',  
  15. SCOPE_GROUPS = 'manage_groups'; 
  16.  
  17. /** 
  18. * Dialog form factors 
  19. * @var string 
  20. */ 
  21. const DISPLAY_PAGE = 'page',  
  22. DISPLAY_POPUP = 'popup',  
  23. DISPLAY_MOBILE = 'mobile'; 
  24.  
  25. /** 
  26. * {@inheritdoc} 
  27. */ 
  28. public function __construct( 
  29. CredentialsInterface $credentials,  
  30. ClientInterface $httpClient,  
  31. TokenStorageInterface $storage,  
  32. $scopes = array(),  
  33. UriInterface $baseApiUri = null 
  34. ) { 
  35. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri); 
  36.  
  37. if (null === $baseApiUri) { 
  38. $this->baseApiUri = new Uri('https://api.dailymotion.com/'); 
  39.  
  40. /** 
  41. * {@inheritdoc} 
  42. */ 
  43. public function getAuthorizationEndpoint() 
  44. return new Uri('https://api.dailymotion.com/oauth/authorize'); 
  45.  
  46. /** 
  47. * {@inheritdoc} 
  48. */ 
  49. public function getAccessTokenEndpoint() 
  50. return new Uri('https://api.dailymotion.com/oauth/token'); 
  51.  
  52. /** 
  53. * {@inheritdoc} 
  54. */ 
  55. protected function getAuthorizationMethod() 
  56. return static::AUTHORIZATION_METHOD_HEADER_OAUTH; 
  57.  
  58. /** 
  59. * {@inheritdoc} 
  60. */ 
  61. protected function parseAccessTokenResponse($responseBody) 
  62. $data = json_decode($responseBody, true); 
  63.  
  64. if (null === $data || !is_array($data)) { 
  65. throw new TokenResponseException('Unable to parse response.'); 
  66. } elseif (isset($data['error_description']) || isset($data['error'])) { 
  67. throw new TokenResponseException( 
  68. sprintf( 
  69. 'Error in retrieving token: "%s"',  
  70. isset($data['error_description']) ? $data['error_description'] : $data['error'] 
  71. ); 
  72.  
  73. $token = new StdOAuth2Token(); 
  74. $token->setAccessToken($data['access_token']); 
  75. $token->setLifeTime($data['expires_in']); 
  76.  
  77. if (isset($data['refresh_token'])) { 
  78. $token->setRefreshToken($data['refresh_token']); 
  79. unset($data['refresh_token']); 
  80.  
  81. unset($data['access_token']); 
  82. unset($data['expires_in']); 
  83.  
  84. $token->setExtraParams($data); 
  85.  
  86. return $token; 
  87.  
  88. /** 
  89. * {@inheritdoc} 
  90. */ 
  91. protected function getExtraOAuthHeaders() 
  92. return array('Accept' => 'application/json');