Android Question SharePoint Online _api

Hi,

we use HttpJob to read data from SharePoint online.

Dim j As HttpJob
j.Initialize("", Me)

j.Download("https://xxxxx.sharepoint.com/sites/...e='ContentSearchRegular'&SelectProperties='*'")

j.Username = "xxxx"
j.Password = "xxxxx"

But we receive this error

ResponseError. Reason: Forbidden, Response: <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="de-DE">Attempted to perform an unauthorized operation.</m:message></m:error>

<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="de-DE">Attempted to perform an unauthorized operation.</m:message></m:error>

User Name and Password are ok :)

We think it is was wrong with the Authentication method but we don't know how to set it rightly .

Thank you for the help!
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Hi,

sorry but was should I in YOUR KEY write?

Dim basicAuth as string = "YOUR KEY"
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://api.octopus.energy/v1/electricity-meter-points/1460001714995/meters/15P0459914/consumption/")
j.GetRequest.SetHeader("Authorization", "Basic " & basicAuth)
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release

Username and Password? In wich form?

or ist this the rigth code? In this case in witch forn shoult i write username and passord?

Dim basicAuth As String = "YOUR KEY:" ' I'm pretty sure you need the colon here at the end of you API key. If you get an error message, take it out and see what happens
Dim su As StringUtils ' requires StringUtils library to be checked
Dim authInfo = su.EncodeBase64(basicAuth.GetBytes("UTF8"))
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://api.octopus.energy/v1/electricity-meter-points/1460001714995/meters/15P0459914/consumption/")
j.GetRequest.SetHeader("Authorization", $"Basic ${authInfo}"$) '<--- only other change (using right variable and, well, SmartStrings)
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release

thank you for your help :)
Claudio
 
Upvote 0
Hi,

I try this

1650349410793.png


But the Result are the same

ResponseError. Reason: Forbidden, Response: <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="de-DE">Attempted to perform an unauthorized operation.</m:message></m:error>

<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="de-DE">Attempted to perform an unauthorized operation.</m:message></m:error>

What ist wrong in this kode? :)

Whit SharePoint Search Query Tool we use this Authentication and it works ...

1650349522434.png


thank you
Claudio
 

Attachments

  • 1650349321460.png
    1650349321460.png
    11.7 KB · Views: 169
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi,

I try this

View attachment 128090

But the Result are the same

ResponseError. Reason: Forbidden, Response: <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="de-DE">Attempted to perform an unauthorized operation.</m:message></m:error>

<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="de-DE">Attempted to perform an unauthorized operation.</m:message></m:error>

What ist wrong in this kode? :)

Whit SharePoint Search Query Tool we use this Authentication and it works ...

View attachment 128091

thank you
Claudio

Wrong. Read well
B4X:
Dim basicAuth As String = "[email protected]:5rt678g" 
Dim su As StringUtils ' requires StringUtils library to be checked
Dim authInfo = su.EncodeBase64(basicAuth.GetBytes("UTF8"))
Dim j As HttpJob
j.Initialize("", Me)
j.Download("htpps://fructusmerano.sharepoint....")
j.GetRequest.SetHeader("Authorization", $"Basic ${authInfo}"$) 
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release

isnt j.GetRequest.SetHeader("Authorization", "service...")
 
Upvote 0
Hi Marco,

I try this but it does not work.

Dim j As HttpJob
Dim basicAuth As String = "[email protected]:xxxxxxx"
Dim su As StringUtils
Dim authInfo As String = su.EncodeBase64(basicAuth.GetBytes("UTF8"))

j.Initialize("", Me)
j.Download("https://fructusmeran.sharepoint.com...e='ContentSearchRegular'&SelectProperties='*'")

j.GetRequest.SetHeader("Authorization", $"Basic ${authInfo}"$)

Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log( j.GetString )
result = j.GetString
Else
Log( j.ErrorMessage )
End If

j.Release

The resuiult are the same als before

ResponseError. Reason: Forbidden, Response: <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="de-DE">Attempted to perform an unauthorized operation.</m:message></m:error>

thank you Claudio
 
Upvote 0
Top