0

我使用团队合作项目管理工具。我正在尝试使用团队合作提供的 REST api 创建一个 Web 应用程序。但这需要一些身份验证。我已经阅读了团队合作文档,这就是他们所说的

验证

使用 HTTP 身份验证管理身份验证(目前仅支持“基本”)。每个请求都必须包含 Authorization HTTP 标头。使用您的 API 令牌作为用户名,并使用“X”(或其他一些虚假文本)作为密码(仅 API 令牌用于验证 API 请求)。

卷曲示例:

curl -H 'Accept: application/json' -H 'Content-Type: application/json' \
-u APIKEY0123456789:xxx -d '{"request": {"name": "some value"}}' https://yours.teamwork.com

我查看了一些在线教程并编写了以下代码

public function portalLogin()
{
        //cURL
        // phpinfo(); //curl is enabled
    $channel = curl_init();
    //options
    curl_setopt($channel, CURLOPT_URL, "http://projects.abounde.com/projects.json?status=LATE");
    curl_setopt($channel, CURLOPT_HTTPHEADER, array("Authoritation:BASIC".base64_encode("secretApiCode:xxx")));
    echo curl_exec($channel);  //return 1
    curl_close($channel);
}

这返回 1。我不知道这是什么意思。我不知道我是否做对了。这是受身份验证保护的团队合作 api 所在的位置。

http://projects.abounde.com/projects.json

我的最终目标是为不同的用户提供不同的用户名和密码,他们将输入这些用户名和密码,系统将从数据库中找到密钥并从特定用户加载项目列表。

4

1 回答 1

1
public function portalLogin()
{
        //cURL
        // phpinfo();
    $username = "night720elvis";
    $password = "xxx";
    $channel = curl_init();
    //options
    curl_setopt($channel, CURLOPT_URL, "http://projects.abounde.com/projects.json?status=LATE");
    //curl_setopt($channel, CURLOPT_HTTPHEADER, array("Authoritation:BASIC".base64_encode("night720elvis:xxx")));

    curl_setopt($channel, CURLOPT_HTTPHEADER,
                array(
                  "Authorization: Basic " . base64_encode($username . ":" . $password)
    ));
    echo curl_exec($channel);
    curl_close($channel);
}

这验证

于 2016-08-08T11:50:07.737 回答