- file_get_contents: documentation ( source)
- stream_context_create: documentation ( source)
- str_replace: documentation ( source)
- session_start: documentation ( source)
- http_build_query: documentation ( source)
- header: documentation ( source)
<?php
session_start();
$redirect_uri = 'http://path/to/app/callback';
$url = 'https://getpocket.com/v3/oauth/request';
$data = array('consumer_key' => '27963-b8ab8bc16d50240c6b5aa93b', 'redirect_uri' => $redirect_uri);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded; charset=UTF-8",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$request_token = str_replace('code=','',$result);
$_SESSION['request_token'] = $request_token;
header("Location: https://getpocket.com/auth/authorize?request_token=$request_token&redirect_uri=$redirect_uri");
die();
?>