Can not send OAuth 2.0 token to google via Outlook VBA - vba

I am trying to update my Google Calendar from a desktop version of Outlook. When I add an event to my outlook calendar, the following VBA code is executed:
Set httpCall = CreateObject("MSXML2.ServerXMLHTTP")
Dim sURL As String
sURL = "https://www.googleapis.com/calendar/v3/calendars/<my google gmail account>/events?sendNotifications=false&fields=etag%2ChtmlLink%2Cid&pp=1&access_token=<my OAuth 2.0 client id>"
httpCall.Open "POST", sURL, False
httpCall.setRequestHeader "Content-Type", "application/json;charset=UTF-8"
httpCall.Send Json
Dim sReturn As String
sReturn = httpCall.responseText
The value of sReturn at the end of executing the code is this:
I have an OAuth 2.0 client id and client secret but obviously, I dont have something set up correctly.
Any assistance is greatly appreciated.
Thank you.

The error message says you need to pass an access token or other valid authentication credentials to get the job done. The code is not authorized.
You may find the Google APIs and Google Oauth2 VBA authentication pages helpful.

In order to write to a users calendar you need their permission. Once you have their permission you should have an access token. This access token must be sent as an authorization header along with your request.
hReq.setRequestHeader "Authorization", "Bearer cHBzX2NyZWdJIYXAhjhjdjsfhjdshakjfdhakfhjk5c0AjMTZAY3JlZ"
I am trying to update my google cleandar
i recommend using calendar.patch instead of calendar update.
Dont for get you need to authorize the user with the following scope
Insert Event
While you have stated that you are trying to update your google calendar, from your code and the erro message it actually looks like you are trying to create a new event using events.isnert
If you are using this method remember it requires that you authorize the user with one of these scopes

Related

Calling Google Sheets API from Zoho Deluge function: The API Key and the authentication credential are from different projects

I am trying to read a Google Sheet by calling the Sheets API from a Zoho CRM Deluge function. I have created a project in the Google Developer Console and input the Key into the 'invokeurl' parameters. When I try to execute the call, I get the error:
"The API Key and the authentication credential are from different projects."
I tried creating an OAuth client ID, but the Google Sheets API only accepts Access Tokens. I admit, I don't know how to programmatically get an access token without giving consent with a pop up (not an option here).
I tried creating an access token using the Google OAuth Playground, but got the same "different projects" error.
I read on a Zoho support article that adding the headers:
{"X-HTTP-Method-Override":"PATCH","Content-Type":"application/json"}
help call Google APIs. When I did that, I get a different error:
"The requested URL /v4/spreadsheets/[spreadsheet ID]/values/[range]?key=[my key] was not found on this server. That’s all we know.
I have no other ideas. Any help would be greatly appreciated.
For reference, here is the relevant portion of the Zoho function:
params =
{
"key":myKey
};
sheet = invokeurl
[
url :"https://sheets.googleapis.com/v4/spreadsheets/" + id + "/values/" + range
type :GET
parameters:params
connection:"to_google_sheets"
headers: {"X-HTTP-Method-Override":"PATCH","Content-Type":"application/json"}
];
Turns out that since I had made a "connection" to the Google Sheets API in the Zoho CRM, I didn't need to pass the Key.
Removing that line made it work just fine.

Spotify API scopes not being recognized - not able to access user info

I am currently implementing a feature that you have the ability to save a song displayed on my iOS application (written with Swift) and this save button allows the song to be appended to the user's Spotify library. According to the Spotify Developer guide, the only scope required for this feature is user-library-modify when authorizing the app with the user. The url to be opened goes like this:
https://accounts.spotify.com/authorize/?client_id=my_client_id&response_type=code&scope=user-library-modify&redirect_uri=http://my_redirect_uri
This all works perfectly - the url is opened for the user to approve of the changes my app can make and the callback url with the required code is in the url is opened.
The next step in performing the required function is to get an exact token in order to use the api, which is done by calling the url:
https://accounts.spotify.com/api/token?grant_type=client_credentials&client_id=my_client_id&client_secret=my_client_secret&response_type=code&redirect_uri=http://my_redirect_uri&code=the_code_I_just_retrieved
With this url, a json file is returned with the new token and info with it, BUT when looking at the permitted scopes the token has, it is empty:
["scope": , "token_type": Bearer, "access_token": the_token_string, "expires_in": 3600]
Also, when I still try to perform the request it returns:
["error": {
message = "Insufficient client scope";
status = 403;
}]
In this lengthy process, what am I doing wrong? In case you are wondering, here are a few things I have tried without success:
1) Re-listing the scopes in the explicit token request
2)Adding utf-8 encoding to the redirect uri (not sure if this changes anything)
3)Adding many other scopes (although this clearly does not target the problem)
If anyone knows what I am doing wrong or has any suggestions as to what I should try, I am grateful for any helpful response!
I have found my mistake. The grant_type I have entered in my url set to client_credentials. However, this method of accessing the web API only permits the usage of publicly available data, not user info. Therefore, this method of authorization does not accept the parameter scope, forcing the spotify account service to ingnore this additional parameter. The other options DO allow accessing the user data, which are:
authorization_code, and refresh_token
The way this now has to be done is to:
1) Authorize the user regularly (with supplying the scopes) to retrieve the initial authorization code
2) Then, with this code, make the token request, but specifying the grant_type to be set as authorization_code
3) You have then received a valid access_token valid for one hour AND a refresh_token
4) Use the access_token when necessary and when this token expires, make another token request, but this time with the grant_type set as refresh_token and setting the code parameter to the previously gained refresh_token
5) You now have the next access_token and refresh_token
6) Repeat steps 4-5 until infinity

RESTful API call from Excel VBA

I'm attempting to access the online API of http://api.football-data.org/index using Excel VBA to eventually populate an excel sheet with a click of a button. Currently I have:
Sub apiTest()
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", "http://api.football-data.org/v1/competitions/354/fixtures/?matchday=22", False
oRequest.SetRequestHeader "X-Auth-Token", "replace this with my api token"
oRequest.Send
MsgBox oRequest.ResponseText
End Sub
According to the site, all I need to do is to add the X-Auth-Token field to the header and it should work. However, when I try to run this the response body says "The resource you are looking for is restricted". Am I using WinHTTPRequest improperly?
I have checked its documentation. The error (403 Restricted Resource) is to do with the followings:
the resource is only available to authenticated clients
the resource is only available to donating clients
the resource is not available in the API version you are using
Also, X-Response-Control seems to be included as request header (See the doc).

API Authorization token error

I'm trying to use the Survey API.
When I try and use the form online to request an Authorization token I get a
error message.
Invalid or missing access token" error message.
The form to test the API calls also asks for a Client Secret code but yet it auto fills the box with the API Key.
Any help here would be nice.
I'm not sure if this is a bug on Survey Monkey's end either in the API or the form that tests the API.
You should have received a reply to this via email but I wanted to ensure this was answered here in case anyone else is having the same issue.
There was a bug on our API console preventing an access token being issued, this is now fixed.
The access token has to be copied into the "Authorization" parameter in the format "bearer ". e.g. if your access token is 'fdhjfu3cc8ss=', make sure the Authorization parameter has "bearer fdhjfu3cc8ss=" in it (with no quotes). Note that you need to use the Access Token returned, not the Authorization Code.

Tumblr API - OAuth issues: OAuth verifier and RESTConsole

Trying to obtain blog followers using Tumblr's API and RESTConsole in Chrome (not building an app, just want to check a request response).
I'm new to Tumblr's API and to RESTConsole, so two sources of possible error here.
I've already ...
Registered an app on Tumblr, receiving OAuth Consumer Key and Secret Key in the process.
Entered into REST Console my target: http://api.tumblr.com/v2/blog/{blogname}.tumblr.com/followers
Entered into REST Console's "Setup oAuth" window my OAuth Consumer Key and Secret Key, along with Tumblr's Request Token URL, Access Token URL and Authorize URL.
Approved read/write access to my application when prompted by Tumblr.
Entered the provided Token Key and Token Secret into REST Console's oAuth window.
When I attempt GET requests for follower counts (on my own blog or others'), Tumblr returns 401, "Not Authorized." My blog's preferences page lists the application I'm trying to use as having access.
I've tried this placing base-hostname:{blogname}.tumblr.com in REST Console's request parameters fields; I receive the same error. I tried running a different OAuth method from Tumblr's API (queued posts) and receive the same error.
Help?
Thanks. Let me know if this isn't clear.
Edit: Sorry, meant to add -- I think I may need Oauth Verifier. I haven't been able to find this token, or understand how to obtain it.
Edit (2): So, turns out Tumblr's API needs a comma separator from the REST Console. Thanks all.
''
Zack
$conskey = "CONSUMER KEY";
$conssec = "CONSUMER SECRET";
$tumblr_blog = "myblog.tumblr.com";
$to_be_posted = "This is the text to be posted";
$oauth = new OAuth($conskey,$conssec);
$oauth->fetch("http://api.tumblr.com/v2/user/following", array('offset'=>0) ,OAUTH_HTTP_METHOD_GET);
$result = json_decode($oauth->getLastResponse());
foreach($result->response->blogs as $key){
echo $key->url;
}
The code above will retrieve your followers list.
Hope this helps.