# Get app access token with PHP

**URL:** <https://staging-discuss.dev.twitch.com/t/get-app-access-token-with-php/27079>\
**Category:** API\
**Created:** [July 12, 2020, 5:34pm UTC](https://staging-discuss.dev.twitch.com/t/get-app-access-token-with-php/27079 "2020-07-12T17:34:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xep22](https://avatars.discourse-cdn.com/v4/letter/x/b5a626/32.png) [@xep22](https://staging-discuss.dev.twitch.com/u/xep22)\
**Post date:** [July 12, 2020, 5:34pm UTC](https://staging-discuss.dev.twitch.com/t/get-app-access-token-with-php/27079/1 "2020-07-12T17:34:58Z")

</div>

hi,

I’m trying to refresh my access token with that PHP script, shown like here:

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

my php code to send the POST request is :

```
$client_id = 'XXX';
$client_secret = 'XXX';

$url = 'https://id.twitch.tv/oauth2/token';
$data = array('client_id' => $client_id, 'client_secret' => $client_secret, 'grant_type' => 'client_credentials');

$options = array(
	'http' => array(
		'header' => "Content-type: application/x-www-form-urlencoded\r\n",
		'method' => 'POST',
		'content' => http_build_query($data)
	)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {}

var_dump($result);

```

But I get this “error”:

> bool(false)

The script worked 2 month ago. did they changed something ?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 12, 2020, 7:47pm UTC](https://staging-discuss.dev.twitch.com/t/get-app-access-token-with-php/27079/2 "2020-07-12T19:47:10Z")

</div>

Ideally you would be using cURL here instead of file\_get\_contents with a stream.

This would suggest your host is now blocking file\_get\_contents ability to make HTTP requests

---

<div class="post-metadata">

**Author:** ![xep22](https://avatars.discourse-cdn.com/v4/letter/x/b5a626/32.png) [@xep22](https://staging-discuss.dev.twitch.com/u/xep22)\
**Post date:** [July 12, 2020, 7:54pm UTC](https://staging-discuss.dev.twitch.com/t/get-app-access-token-with-php/27079/3 "2020-07-12T19:54:05Z")

</div>

thanks works now!

---

<div class="post-metadata">

**Author:** ![system](https://d2spem0quai2ol.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://staging-discuss.dev.twitch.com/u/system)\
**Post date:** [August 11, 2020, 7:54pm UTC](https://staging-discuss.dev.twitch.com/t/get-app-access-token-with-php/27079/4 "2020-08-11T19:54:07Z")

</div>

Closed on August 11, 2020, 7:54pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
