dongwei3120 2019-08-09 01:54
浏览 494

Laravel卷曲请求导致了“403 Forbidden”响应

I am working on a laravel based project and I need to import time entries from Toggl account. Toggl seems to have correct API in place but I am not able to pull records via API for some reason.

I am using the below-mentioned library to access Toggl API. https://medium.com/laravel-5-the-right-way/using-guzzlehttp-with-laravel-1dbea1f633da

I am getting below error on every request to API. GuzzleHttp \ Exception \ ClientException (403) Client error: GET https://toggl.com/api/v8/time_entries?user_agent=deepak%40gmail.com&workspace_id=257895&with_related_data=1 resulted in a 403 Forbidden response

I have tried to fix it by adding or removing (below-mentioned) header elements that are sent with each request. But it still does not work.

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;

$client = new Client;
$credentials = base64_encode('e5e8238ca0fee3ca726e486733c87456:api_token');
$url = 'https://toggl.com/api/v8/time_entries';

$response = $client->get($url,
    [
        'referer' => true,
        'headers' => [
            'Authorization: Basic ' => $credentials,
            'Content-Type: application/json',
            'User-Agent' => 'Mozilla /5.0 (Compatible MSIE 9.0;Windows NT 6.1;WOW64; Trident/5.0)',
            'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding' => 'gzip, deflate, br',
        ],

        'query' => [
            'user_agent' => 'deepak@gmail.com',
            'workspace_id' => '8756952',
            'with_related_data' => true,

        ],
        "http_errors" => false,
    ]);
dd($response);

It should retrieve the records from Toggl and print a JSON on the browser.

Interestingly, I am able to pull records through the command-line interface using the command below. curl -v -u e5e8238ca0fee3ca726e486733c85468:api_token -X GET https://www.toggl.com/api/v8/time_entries

Please know that in the above code snippet, I have changed the API key for obvious reasons.

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决