简体   繁体   中英

Dropbox api get access token PHP

I try to get Dropbox access token using PHP,

https://www.dropbox.com/developers-v1/core/docs#request-token

I made 2 php files,

auth.php:

$Header = array(
"Authorization: OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\", oauth_consumer_key=\"XXX\", oauth_signature=\"XXX&\"\r\n"
);

$Options = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => $Header,
    )
);


$Context  = stream_context_create($Options);
$Result = file_get_contents("https://api.dropbox.com/1/oauth/request_token", false, $Context);

echo '<a target="_blank" href="https://www.dropbox.com/1/oauth/authorize?'.$Result.'&oauth_callback=http://localhost/dropbox/access_token.php">auth</a>';

auth.php file is working good! and redirect me to dropbox site to accept me app

but when redirect to access_token.php file, i can't get my access token!

I got error: failed to open stream: HTTP request failed! HTTP/1.1

access_token.php file:

 $Options = array('http' =>
    array(
        'method'  => 'POST',
    )
);

$au = $_GET['oauth_token'];

$Context  = stream_context_create($Options);
$Result = file_get_contents("https://api.dropboxapi.com/1/oauth/access_token?oauth_token=$au", false, $Context);

print_r($Result);

Check selinux setting for httpd_network_connect in Apache. It seems that file get content fails to open the stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM