Пример #1
0
    echo NEWLINE;
    // Add a url to the user's pocket
    // http://getpocket.com/developer/docs/v3/add for a list of params
    $params = array('url' => 'https://github.com/djchen/', 'tags' => 'github');
    print_r($pocket->add($params, $user['access_token']));
    echo NEWLINE;
    // Retrieve the user's list of unread items (limit 5)
    // http://getpocket.com/developer/docs/v3/retrieve for a list of params
    $params = array('state' => 'unread', 'sort' => 'newest', 'detailType' => 'simple', 'count' => 5);
    $items = $pocket->retrieve($params, $user['access_token']);
    print_r($items);
} else {
    // Attempt to detect the url of the current page to redirect back to
    // Normally you wouldn't do this
    $redirect = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?authorized=';
    // Request a token from Pocket
    $result = $pocket->requestToken($redirect);
    /*
    	$result['redirect_uri']		this is the URL to send the user to getpocket.com to authorize your app
    	$result['request_token']	this is the request_token which you will need to use to
    					obtain the user's access token after they have authorized your app
    */
    /*
    This is a hack to redirect back to us with the requestToken
    Normally you should save the 'request_token' in a session so it can be
    retrieved when the user is redirected back to you
    */
    $result['redirect_uri'] = str_replace(urlencode('?authorized='), urlencode('?authorized=' . $result['request_token']), $result['redirect_uri']);
    // END HACK
    header('Location: ' . $result['redirect_uri']);
}