MQL4: Webrequest "GET" issue with shared file on google drive

 

Hey programmers

I don't get any further with my simple webrequest to a google drive file, to just pull out a simple word, how the sentiment of nas100 is. (https://drive.google.com/file/d/1Cu9HVjzxKZoZ5E1z_hYL1wO0pKWfz2jC/view?usp=sharing)
I always get an 404 Error when trying to access the file over the webrequest. The file is public viewable, and i already tried different aproaches:
- Google Drive API Key, and use another URL to access the file
- use the viewing file ID in browser
- with or without the user agent in the headers, also with other necessary fields to mimic a browser request

the strange thing is, in a browser it works perfectly, so i know that the file is acessible and the URL is correct, also in mt4 itself i granted access to do a webrequest on the specific url of google drive.

is there anyone who can help me to fix this?

here is my code, that simple checks if it works on init:

extern string sentimentFileURL = "https://drive.google.com/uc?export=download&id=1Cu9HVjzxKZoZ5E1z_hYL1wO0pKWfz2jC";
string sentiment;

// Fetch sentiment from URL using simple headers
string FetchSentimentFromURL(string url)
{
    string headers = "User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36\r\n";
    char post[], result[];
    string result_headers;
    int timeout = 10000; // 10 seconds

    ResetLastError();
    int res = WebRequest("GET", url, headers, timeout, post, result, result_headers);

    if (res == -1)
    {
        Print("Error in WebRequest. Error code =", GetLastError());
        MessageBox("Add the address '" + url + "' in the list of allowed URLs on tab 'Expert Advisors'", "Error", MB_ICONINFORMATION);
        return "";
    }
    else if (res == 200)
    {
        PrintFormat("The file has been successfully loaded, File size = %d bytes.", ArraySize(result));
        PrintFormat("HTTP Response Code: %d", res);
        Print("Response Headers: ", result_headers);

        string resultString = CharArrayToString(result);
        return resultString;
    }
    else
    {
        PrintFormat("HTTP Response Code: %d", res);
        Print("Response Headers: ", result_headers);
        return "";
    }
}

string CharArrayToString(char &arr[])
{
    string result = "";
    for (int i = 0; i < ArraySize(arr); i++)
    {
        result += CharToString(arr[i]);
    }
    return result;
}


//


// init

int init()
{
sentiment = FetchSentimentFromURL(sentimentFileURL);
Print(sentiment);
}


p.p1 {margin: 0.0px 0.0px 0.0px 21.0px; text-indent: -21.0px; font: 14.0px '.SF NS'; color: #0e0e0e}
 

Result with the link provided by the OP:


Result with the link provided by ChatGPT: