简体   繁体   English

Dropbox API获取访问令牌PHP

[英]Dropbox api get access token PHP

I try to get Dropbox access token using PHP, 我尝试使用PHP获取Dropbox访问令牌,

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

I made 2 php files, 我做了2个php文件,

auth.php: 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! auth.php文件运行良好! and redirect me to dropbox site to accept me app 并将我重定向到Dropbox网站以接受我的应用

but when redirect to access_token.php file, i can't get my access token! 但是当重定向到access_token.php文件时,我无法获得访问令牌!

I got error: failed to open stream: HTTP request failed! 我收到错误消息:无法打开流:HTTP请求失败! HTTP/1.1 HTTP / 1.1

access_token.php file: access_token.php文件:

 $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. 检查Apache中httpd_network_connect的selinux设置。 It seems that file get content fails to open the stream. 似乎文件获取内容无法打开流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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