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 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 MATLAB中streamslice问题
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序