简体   繁体   English

致命错误:消息为“ code”的未捕获异常“ InvalidArgumentException”必须为非空

[英]Fatal error: Uncaught exception 'InvalidArgumentException' with message ''code' must be non-empty'

I am trying to display the dropbox folders and files using PHP. 我正在尝试使用PHP显示Dropbox文件夹和文件。 Meanwhile I am getting the below error: 同时,我收到以下错误:

Fatal error: Uncaught exception 'InvalidArgumentException' with message ''code' must be non-empty' in D:\\xampp\\htdocs\\Dropbox\\dropbox\\Dropbox\\Checker.php:59 Stack trace: #0 D:\\xampp\\htdocs\\Dropbox\\dropbox\\Dropbox\\WebAuthNoRedirect.php(79): Dropbox\\Checker::argStringNonEmpty('code', '') #1 D:\\xampp\\htdocs\\Dropbox\\dropbox.php(24): Dropbox\\WebAuthNoRedirect->finish('') #2 {main} thrown in D:\\xampp\\htdocs\\Dropbox\\dropbox\\Dropbox\\Checker.php on line 59 致命错误:D:\\ xampp \\ htdocs \\ Dropbox \\ dropbox \\ Dropbox \\ Checker.php:59中未捕获的异常“ InvalidArgumentException”消息为“ code”必须为非空堆栈跟踪:#0 D:\\ xampp \\ htdocs \\ Dropbox \\ dropbox \\ Dropbox \\ WebAuthNoRedirect.php(79):Dropbox \\ Checker :: argStringNonEmpty('code','')#1 D:\\ xampp \\ htdocs \\ Dropbox \\ dropbox.php(24):Dropbox \\ WebAuthNoRedirect- > finish('')#2 {main}在第59行的D:\\ xampp \\ htdocs \\ Dropbox \\ dropbox \\ Dropbox \\ Checker.php中抛出

This is my code: 这是我的代码:

<?php
require_once "dropbox/Dropbox/autoload.php";
require_once "dropbox/Dropbox/AppInfo.php";
use \Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile("app-info.json");
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");


if(!function_exists("readline")) {
    function readline($prompt = null){
        if($prompt){
            //echo $prompt;
        }
        $fp = fopen("php://stdin","r");
        $line = rtrim(fgets($fp, 1024));
        return $line;
    }
}


$authorizeUrl = $webAuth->start();
$authCode = \trim(\readline("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
print "Access Token: " . $accessToken . "\n"; 
?>

The error is coming from $webAuth->finish() function.From the error i checked the checker.php.There is one function has been defined.That is 错误来自$ webAuth-> finish()函数。从错误中我检查了checker.php。已经定义了一个函数。

static function argStringNonEmpty($argName, $argValue)
    {
        if (!is_string($argValue)) self::throwError($argName, $argValue, "string");
        if (strlen($argValue) === 0) throw new \InvalidArgumentException("'$argName' must be non-empty");
    }

If i command the condition the error keep on moving to the next next function.Please help how to solve it. 如果我命令该条件,错误将继续移至下一个下一个函数。请帮助解决问题。

It looks like you're the API v1 Dropbox PHP SDK . 看来您是API v1 Dropbox PHP SDK Your code looks similar to the "authorize" example . 您的代码看起来类似于“授权”示例 That sample is built for a command line app, but you're trying to run it as a web app, so it won't work. 该示例是为命令行应用程序构建的,但是您尝试将其作为Web应用程序运行,因此它将无法正常工作。

Specifically, you're trying to read from stdin (like how the example uses \\trim(\\fgets(STDIN)) ). 具体来说,您正在尝试从stdin中读取内容(例如该示例如何使用\\trim(\\fgets(STDIN)) )。

For a web app, you should instead refer to the web-file-browser example . 对于Web应用程序,您应该参考web-file-browser示例

In either case, you would need to supply the "authorization code" to complete the OAuth app authorization flow . 无论哪种情况,您都需要提供“授权代码”以完成OAuth应用授权流程

Also, it's important to note that that PHP SDK uses Dropbox API v1, which is deprecated . 另外,请务必注意,PHP SDK使用了不推荐使用的Dropbox API v1 You should migrate to Dropbox API v2 instead. 您应该改为迁移到Dropbox API v2

There isn't an official PHP SDK for Dropbox API v2, but you can use a third party library or you can call the HTTPS endpoints themselves. 没有适用于Dropbox API v2的官方PHP SDK,但是您可以使用第三方库 ,也可以自己调用HTTPS端点

I have changed my code like below: 我已经更改了我的代码,如下所示:

session_start();
$_SESSION['user_id'] = 1;

require __DIR__.'/Dropbox/autoload.php';

$dropboxKey = 'XXXXXXXXX';
$dropboxSecret = 'XXXXXXXXXX';
$appName = 'XXXXXXX/1.0';

$appInfo=new Dropbox\AppInfo($dropboxKey,$dropboxSecret);

//store CSRF token
$csrfTokenStore = new Dropbox\ArrayEntryStore($_SESSION,'dropbox-auth-csrf-token');

//Define auth details
$webAuth = new Dropbox\WebAuth($appInfo,$appName,'http://localhost/dropboxapi/dropbox_finish.php',$csrfTokenStore);

if(isset($_session['accessToken']))
{
    $client = new Dropbox\Client($_session['accessToken'],$appName,'UTF-8');
    $client->getAccountInfo();
} else {
$authUrl = $webAuth->start();

Header('Location:'.$authUrl);
exit;
}
list($accessToken) = $webAuth->finish($_GET);

$_session['accessToken']=$accessToken;

暂无
暂无

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

相关问题 Magento 2-致命错误:未捕获的异常&#39;InvalidArgumentException&#39; - Magento 2 - Fatal error: Uncaught exception 'InvalidArgumentException' 致命错误:未捕获的 InvalidArgumentException: - Fatal error: Uncaught InvalidArgumentException: Mailgun:致命错误:带有消息“无法打开”的未捕获异常“ Guzzle \\ Common \\ Exception \\ InvalidArgumentException” - Mailgun : Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open Slim框架致命错误:未捕获异常&#39;InvalidArgumentException&#39;,消息&#39;无法创建LogWriter - Slim framework Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Cannot create LogWriter 致命错误:消息为“ 1048”的未捕获异常“ Exception” - Fatal error: Uncaught exception 'Exception' with message '1048 PHP致命错误:带有消息的未捕获异常“异常” - PHP fatal error: Uncaught exception 'Exception' with message 致命错误:消息为“ DateTimeZone ::?”的未捕获异常“ Exception” - Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::? 致命错误:消息&#39;DateTime ::&#39;未捕获异常&#39;Exception&#39; - Fatal error: Uncaught exception 'Exception' with message 'DateTime:: PHPExcel-致命错误:带有消息的未捕获异常“ Exception” - PHPExcel - Fatal error: Uncaught exception 'Exception' with message 致命错误:消息为“序列化的”的未捕获异常“ Exception” - Fatal error: Uncaught exception 'Exception' with message 'Serialization of
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM