none
Error 401 Power BI API

    Pertanyaan

  • I'm making a workaround to pick up the power BI upgrade history but I'm getting 401 return, I've already released all permissions for the application. I can generate the token normally, but when I try to get the groups I get "Unauthorized access", do you have any idea what I need to verify?

    my code

    getData("https://api.powerbi.com/v1.0/myorg/groups").ToString
    
    Public Function getToken() As String
            Dim objs As RootObject
    
            Dim cliente = New RestClient("https://login.microsoftonline.com/00000000/oauth2/token")
            Dim req = New RestRequest()
    
            req.Method = Method.POST
            req.Parameters.Clear()
            req.AddHeader("Content-Type", "application/x-www-form-urlencoded")
            req.AddParameter("grant_type", "client_credentials", ParameterType.GetOrPost)
            req.AddParameter("client_id", "0000000", ParameterType.GetOrPost)
            req.AddParameter("client_secret", "000000", ParameterType.GetOrPost)
            req.AddParameter("resource", "https://analysis.windows.net/powerbi/api", ParameterType.GetOrPost)
    
    
    
            Dim resposta = cliente.Execute(req)
            Dim content = resposta.Content.ToString
            objs = JsonConvert.DeserializeObject(Of RootObject)(content.ToString)
            Dim token = objs.access_token
            Return (token.ToString)
        End Function
    
    
    Private Function getData(ByVal url As String) As String
            Dim powerBIApiUrl As String = url
            Dim token As String = getToken()
            Dim request As HttpWebRequest = TryCast(System.Net.WebRequest.Create(powerBIApiUrl), System.Net.HttpWebRequest)
            request.KeepAlive = True
            request.Method = "GET"
            request.ContentLength = 0
            request.ContentType = "application/json; charset=utf-8"
    
            request.Headers.Add("Authorization", String.Format("Bearer {0}", token))
    
            Using httpResponse As HttpWebResponse = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
    
                Using reader As StreamReader = New System.IO.StreamReader(httpResponse.GetResponseStream())
                    Dim responseContent As String = reader.ReadToEnd()
    
                    Return responseContent.ToString
                End Using
            End Using
        End Function


    Fabiano Carvalho

    Selasa, 28 Agustus 2018 12.35

Semua Balasan

  • Hi Faabiianooc,

    This forum discusses and asks questions about extending and integrating with Visual Studio, since your issue is more related to Power BI, I would suggest that you could post your issue in Power BI forum for suitable support.

    https://community.powerbi.com/t5/Forums/ct-p/Forums

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Rabu, 29 Agustus 2018 03.03