SugarSync API Retrieving User Information: Error 401 Unauthorized

I am trying to get a request for custom information using functions WinHttp

. REST API request for SugarSync

- link here .

My code looks like this:

DWORD dwBytesWritten = 0;
DWORD dwStatusCode = 0;
DWORD dwSize = sizeof(DWORD);
BOOL  bResults = FALSE;
string data;
HINTERNET hSession = NULL, 
hConnect = NULL,
hRequest = NULL;

WINHTTP_PROXY_INFO proxyInfo;
winhttpintObj.setProxyInfo(proxyInfo);

HINTERNET hSession = WinHttpOpen(  L"A WinHTTP Example Program/1.0", 
                                   WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
                                   WINHTTP_NO_PROXY_NAME, 
                                   WINHTTP_NO_PROXY_BYPASS, 0);

HINTERNET hConnect = WinHttpConnect( hSession, L"api.sugarsync.com",   
                                     INTERNET_DEFAULT_HTTPS_PORT, 0);

HINTERNET hRequest = WinHttpOpenRequest( hConnect, 
                                         L"GET", L"/user/<userID>", 
                                         NULL, 
                                         WINHTTP_NO_REFERER, 
                                         0, 
                                         WINHTTP_FLAG_SECURE);

string header("Authorization: ");
header += (accessToken);
header += "\n";
wstring ws = wstring(header.begin(), header.end());
WinHttpAddRequestHeaders( hRequest, ws.c_str(), (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD );

WinHttpSendRequest( hRequest,
                    WINHTTP_NO_ADDITIONAL_HEADERS,
                    0,
                    WINHTTP_NO_REQUEST_DATA,
                    0, 
                    0, 
                    0 );

WinHttpReceiveResponse( hRequest, NULL);

WinHttpQueryHeaders( hRequest, 
                     WINHTTP_QUERY_STATUS_CODE |
                     WINHTTP_QUERY_FLAG_NUMBER,
                     NULL, 
                     &dwStatusCode, 
                     &dwSize, 
                     NULL );

cout << "dwStatusCode: " << dwStatusCode << endl;

      

accessToken

- https://api.sugarsync.com/authorization/......

. The returned status code 401: Authorization required

. However, I have already indicated it in the title. May I know where the problem is and what is a possible fix? Thank.

+3


source to share





All Articles