Hi all,
I have a current request to download field collected data and pics hosted in ArcGIS Online and format in an Excel table.
In the back end of Excel (VBA) have managed to connect to ArcGIS online and generate a token with the following code
Dim tokenHTTP As Object
Set tokenHTTP <SPAN class="operator token">=</SPAN> <SPAN class="token function">CreateObject</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MSXML2.ServerXMLHTTP"</SPAN><SPAN class="punctuation token">)</SPAN>
Dim tokenJSON As String
Dim tokenURL As String
tokenURL <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2FgenerateToken%3Ff%3Djson%26username%3D" target="_blank">https://www.arcgis.com/sharing/rest/generateToken?f=json&username=</A><SPAN>"</SPAN></SPAN> <SPAN class="operator token">&</SPAN> Me<SPAN class="punctuation token">.</SPAN>userName_Txt<SPAN class="punctuation token">.</SPAN>Value <SPAN class="operator token">&</SPAN> <SPAN class="string token">"&password="</SPAN> <SPAN class="operator token">&</SPAN> Me<SPAN class="punctuation token">.</SPAN>password_Txt<SPAN class="punctuation token">.</SPAN>Value <SPAN class="operator token">&</SPAN> <SPAN class="string token">"&client=requestip&expiration=1"</SPAN>
tokenHTTP<SPAN class="punctuation token">.</SPAN>Open <SPAN class="string token">"POST"</SPAN><SPAN class="punctuation token">,</SPAN> tokenURL<SPAN class="punctuation token">,</SPAN> False
tokenHTTP<SPAN class="punctuation token">.</SPAN>setRequestHeader <SPAN class="string token">"Content-type"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"application/json"</SPAN>
tokenHTTP<SPAN class="punctuation token">.</SPAN>send <SPAN class="punctuation token">(</SPAN>tokenJSON<SPAN class="punctuation token">)</SPAN>
Debug<SPAN class="punctuation token">.</SPAN>Print <SPAN class="punctuation token">(</SPAN>tokenHTTP<SPAN class="punctuation token">.</SPAN>responseText<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
the response looks like this.
{
"token":"hIBzdwwVbXv9k8iIZtr0LBwZ5ujSwCdTrdS6_P1XngsglCLnB2tpiV8u9W-6oMDA9Ggf6EMMd77SmXH6BPszKSGvf_oz9QTnEyt4YsSZ-nCuUDzhxW8j6oaAKET8Hk-4qBnLiXGEpuz8JifBSLwHFg..",
"expires":1541634562738,
"ssl":true
}<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The problem is, when I try to use this token to query a FeatureService like this
Dim httpObj As Object
Set httpObj <SPAN class="operator token">=</SPAN> <SPAN class="token function">CreateObject</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MSXML2.ServerXMLHTTP"</SPAN><SPAN class="punctuation token">)</SPAN>
Dim responseJSON As String
Dim featureServiceURL As String
featureServiceURL <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fservices8.arcgis.com%2Fmyagolid%2Farcgis%2Frest%2Fservices%2Ftest_points%2FFeatureServer%2F0%2Fquery%3Fwhere%3DOBJECTID" target="_blank">https://services8.arcgis.com/myagolid/arcgis/rest/services/test_points/FeatureServer/0/query?where=OBJECTID</A><SPAN>>1&outFields=*&returnHiddenFields=true&returnGeometry=true&returnExceededLimitFeatures=true&f=pgeojson&token="</SPAN></SPAN> <SPAN class="operator token">&</SPAN> agoToken
Debug<SPAN class="punctuation token">.</SPAN>Print <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Get Data from: "</SPAN> <SPAN class="operator token">&</SPAN> featureServiceURL<SPAN class="punctuation token">)</SPAN>
httpObj<SPAN class="punctuation token">.</SPAN>Open <SPAN class="string token">"POST"</SPAN><SPAN class="punctuation token">,</SPAN> featureServiceURL<SPAN class="punctuation token">,</SPAN> False
httpObj<SPAN class="punctuation token">.</SPAN>setRequestHeader <SPAN class="string token">"Content-type"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"application/json"</SPAN>
httpObj<SPAN class="punctuation token">.</SPAN>send <SPAN class="punctuation token">(</SPAN>responseJSON<SPAN class="punctuation token">)</SPAN>
Debug<SPAN class="punctuation token">.</SPAN>Print <SPAN class="punctuation token">(</SPAN>responseJSON<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I get this error?
{
"error" :
{
"code" : 498,
"message" : "Invalid token.",
"details" : [
"Invalid token."
]
}
}<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I cant work out what is going on here? Is it not returning the full length of the token? Or do I have to configure something in my ArcGIS Online account to allow access?
Any help would be much appreciated 
Thanks
James