Using the CreateObject("msxml2.xmlhttp") to extract information from a web-page, I've discovered that null response from getElementsByTagName("table") is experienced when a login is required on said web-page.
I've attempted to overcome this by using the following to set username/password for the login page:
oDom.getElementById("login-form-username").Value = strUser
oDom.getElementById("login-form-password").Value = strPwd
I've subsequently attempted to submit the information using:
oDom.getElementById("login-form-submit").Click
Unfortunately, the .Click does not seem to work. Is there anything else required to in order to submit the information? The strUser and strPwd values are input from InputBox.
Many thanks in advance
G
Related
I am running a script under Outlook whereby when I add an event I execute code which adds the event to a google calendar. I have this code working with Oauth2.0 in place. When I add the event, I pass the event ID to google so the events in the outlook calendar and the google calendar will have the same event ID.
The next thing I need to do is have the ability to delete the google calendar event when the outlook calendar event is deleted. I am trying to follow the example from the Google Calendar for Developers (https://developers.google.com/calendar/api/v3/reference/events/delete#auth). I am executing the following code:
Private Sub DeletedItems_ItemAdd(ByVal Item As Object)
Set httpCall = CreateObject("MSXML2.ServerXMLHTTP")
Dim sURL As String
sURL = "https://www.googleapis.com/calendar/v3/calendars/<my calendarid>/events/" + Item.EntryID
httpCall.Open "DELETE", sURL, False
httpCall.setRequestHeader "Content-Type", "application/json;charset=UTF-8"
httpCall.Send Json
Dim sReturn As String
sReturn = httpCall.responseText
MsgBox (sReturn)
End Sub
The message box that gets displayed says Request is missing required authentication credential. Expected OAuth2 access token, login cookie or other valid authentication credentials. So, I changed the sURL to this:
sURL = "https://www.googleapis.com/calendar/v3/calendars/<my calendarid>/events/" + Item.EntryID + "?access_token=<my access token>"
but now I get this error back: code: 404, message "Not Found"
How do I authenticate a delete request via OAuth2.0 via the google calendar API?
Thank you for any assistance.
I have code which will pass the event ID to the google calendar API but it is failing telling me
First of all, you need to retrieve a valid access token for making such calls. In the string there is a placeholder which should be replaced with a valid value:
<my access token>
Also you need replace another placeholder in the string with a valid calendar ID:
<my calendarid>
The Item.EntryID value is specific to the local store and may not correspond to the ID on the google calendar. Moreover, the EntryID property value can be changed when items are moved to another folder/store. So, I'd suggest using your own IDs instead, so in Outlook you can add a user property to items.
You can read more about calling any Google APIs in the Google Drive API Using Excel VBA article where authentication is covered as well.
I have a basic MS Access application that has a button on a form that should open a webpage with the ID of the Access record as the parameter, but everything I have tried results either in an error by Access or only the base URL opening in the web page.
I have tried adding VBA to the button's click event as so:
Application.FollowHyperlink _
"http://example.com/index.php?r=controller/action&id=" & Me.ID
but all I get is the base URL opening on the web browser (ie http://example.com). If I remove the '?' and the '&' from the full URL the button will open the browser with the full URL minus the '?' and the '&', which of course errors the page.
I have tried setting a hyperlink control's property as:
="http://example.com/index.php?r=controller/action&id=" & Me.ID
but it does the same thing as noted above.
I have tried creating a Macro with the same results. I have tried using the Hyperlink Builder and using [formName]![id] as the parameter but same thing happens or Access errors.
I have read this article: https://msdn.microsoft.com/en-us/library/office/ff822080.aspx and tried adding the part in the URl after 'index.php/ to the ExtraInfo place in the code, but same thing.
Help! It can't be that hard to simply have Access open a URL with a parameter on the end of the URL.
Application.FollowHyperlink is fickle.
Use either ShellExecute:
Open an html page in default browser with VBA?
or
CreateObject("Shell.Application").Open "http://example.com/index.php?r=controller/action&id=" & Me.ID
see https://stackoverflow.com/a/18922262/3820271
If the URL is in a string variable, you may need to cast it to Variant, because that's what Shell.Application.Open expects:
strUrl = "http://example.com/index.php?r=controller/action&id=" & Me.ID
CreateObject("Shell.Application").Open CVar(strUrl)
see https://stackoverflow.com/a/56173911/3820271, thanks Toby and Anthony for pointing this out!
Note that if you are having issues with CreateObject("Shell.Application").Open not working with a variable, it might be a casting issue - try tossing a CVar() around the parameter. See https://stackoverflow.com/a/56173911/8512931 for more details.
I'm a novice and your help has been amazing so far! I have an issue with a GET request for SSO authentication in an Excel Visual Basic script. The API says to send the GET request to:
https://services.example.com/API/Security.svc/SSOSiteLogin/siteId/enterpriseGuid/authToken/timezoneOffset
Where the values for siteID, enterpriseGUID, authToken, and timezoneOffset have all been obtained by previous GET requests, which have worked fine. When I send the final GET request for a security token, it returns:
{"Detail":"SSOSiteLogin failed.Input string was not in a correct format."}
Here is my relevant code:
Dim hreq As New WinHttpRequest
Dim response As String
Dim URL As String
'get security token
URL = "https://services.example.com/API/Security.svc/SSOSiteLogin/siteID/enterpriseGUID/" & authToken & "/null"
hreq.Open "GET", URL, False
hreq.Send
response = hreq.ResponseText
Range("A13") = response
The siteID and enterpriseGUID variables are input into the code, and the authToken is stored from an earlier POST request. The last value, timezoneOffset, is given as "null" from an earlier request so I've been typing "/null" at the end but I'm concerned that's what's triggering the incorrect format response. Anything else just returns a total error from the server though.
Any ideas? Thank you in advance!
I had put the values into cells and was sending the GET request as "Range("E5") & "/" & Range("E6") & "/", etc. so that I could try a couple of debugging issues without having to go to the VBA editor and for some reason that worked! I ended up using the string "null", too. If anyone knows why this worked and inputting it all as one string doesn't I'd be interested to find out.
In the following code strUser gets set correctly on line 3.
However user returns a value of Nothing after line 4 executes.
Dim strUser As String
Dim user As MembershipUser
strUser = gvUsers.SelectedRow.Cells(0).Text
user = Membership.GetUser(strUser)
This code is being used to change the password of another user.
I can find lots of references to code which is for the logged in user but nothing else.
Anyone got any ideas.
Many thanks
Amanda
Worked it out. The UserName and the LoweredUserName were out of sync thus Membership.GetUser could not find the user based on UserName even though it existed.
I am trying to update an old ASP classic Twitter program that my work currently uses to use the new OAUTH. I am not an ASP programmer but I managed to find the ASPTwitter library posted online by Tim Acheson at http://www.timacheson.com/Blog/2013/jun/asptwitter
Everything works, as we have our own code searching our database and passing on a built string to the ASPTwitter code to tweet.
The catch is that it will fail with the
{"errors":[{"message":"Could not authenticate you","code":32}]}
error message if there is so much as a "." period in the string. Every possible special character besides letters and numbers causes a fail.
We have many posts that will include various symbols as well as URLs.
I have searched all over and have not been able to find a solution. Comments on Tim's site have mentioned it but no solutions yet. Everyone here has been very helpful so I was hoping someone might have a solution.
I can't post the code as there are about 6 files and I don't know which one is causing the issue.
Thank you so much for the help!
Edit:
This is a block of the 300+ line file where the issue happens, I hope that the cause can be found here too.
' Gets bearer token for application-only authentication from Twitter API 1.1.
' Application-user authentication: https://dev.twitter.com/docs/auth/using-oauth
' and: https://dev.twitter.com/docs/auth/authorizing-request
' API endpoint statuses/update (post a tweet): https://dev.twitter.com/docs/api/1.1/post/statuses/update
Private Function UpdateStatusJSON(sStatus)
Dim sURL : sURL = API_BASE_URL + "/1.1/statuses/update.json"
Dim oXmlHttp: Set oXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXmlHttp.open "POST", sURL, False
sStatus = "this is from the ASPTwitter dot asp file"
oXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"
oXmlHttp.setRequestHeader "User-Agent", "emiratesjobpost.com"
oXmlHttp.setRequestHeader "Authorization", "OAuth " & GetOAuthHeader(sURL, sStatus)
oXmlHttp.send "status=" & Server.URLEncode(sStatus) ' Encoded spaces as + in request body.
UpdateStatusJSON = oXmlHttp.responseText
Set oXmlHttp = Nothing
REM: A JSON viewer can be useful here: http://www.jsoneditoronline.org/
' To fix error message "Read-only application cannot POST" go to your application's "Application Type" settings at dev.twitter.com/apps and set "Access" to "Read and Write".
' After changing access to read/write you must click the button to generate new auth tokens and then use those.
Response.Write "<textarea cols=""100"" rows=""3"" >" & UpdateStatusJSON & "</textarea>" : Response.Flush()
End Function
If I replace the "dot" with "." in the "sStatus" line, it breaks
Do your pages use UTF-8 encoding? Open them in Notepad, select save as from the file menu, and if ansi coding is selected then change it to UTF-8.
See this link for more things you can do
http://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx