Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Twitter API to Power BI

I'm trying to create an API connection between Twitter and Power BI but I'm having no luck at all.

 

I only need to pull my own user info and not all users historical data.

 

I believe I require an API key, and API access token and a Bearer token which I've been able to get from my Twitter Dev account.

 

My problem is that I need to translate the documented cURL request link into something that Power BI can accept and I have no idea how to go about this.

 

Example cURL request: 

curl 'https://api.twitter.com/2/tweets?ids=1204084171334832128&tweet.fields=public_metrics&expansions=attachments.media_keys&media.fields=public_metrics' --header 'Authorization: Bearer $BEARER_TOKEN'

 

I believe I have to insert some M language code into the "Advanced Editor" in Power Query for this to work but I haven't been able to find any such information on the internet.

 

Any help wuould be most appreciated!

@ImkeF 

@PhilipTreacy 

@CNENFRNL 

6 REPLIES 6
mahoneypat
Employee
Employee

@Anonymous  I see the same error when i re-open that pbix, as I've cancelled the authkey since I've shared this.  Did you go to the Source step and replace the code with yours (keep the "Basic " part)?  Once that is working, you can replace the query part with what you want (q=    ).

 

mahoneypat_0-1609162791189.png

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi @mahoneypat , @PhilipTreacy 

Hope you can help. I used your sample file and i am facing the issue while generating the token number. See below.

M-Query

let
// Basic auth
authKey = "Basic ****************************",
url = "https://api-e2e.danfoss.com/oauth2/token",
// bearer token
GetJson = Web.Contents(url,
[
Headers = [#"Authorization"=authKey,
#"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
Content = Text.ToBinary("grant_type=client_credentials")
]
)
in
GetJson

 

Error msg

 

Peter_Jeyaraj_I_0-1643277494956.png

 

 

See the working http from postman

 

Peter_Jeyaraj_I_1-1643277495144.png

 

thanks in advance for your support

 

 

 

Anonymous
Not applicable

Hi guys!

@PhilipTreacy @mahoneypat 

 

Thanks hugely for your help!

 

I'm still getting no where with this.

PhilipTreacy
Super User
Super User

Hi @Anonymous 

I'm trying to set up my Twitter Dev account but having some issues with Twitter.  Waiting on them to sort it out before I can test this for you.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi, thanks hugely for answering with an example but unfortunatley it doesn't work.

I get the error "Expression.Error: Access to the resource is forbidden."

In that example, was the data being pulled my own user or all Twitters user data?

Once again, your help is greatly appreciated!

mahoneypat
Employee
Employee

I hope this is not out of date, but here this pbix contains an example of getting Twitter data.  You need to use the AuthKey to go get a temporary authentication token to use with your actual data web calls.  I changed the first step (authkey) to not share my key, so you should just need to update that and then change the query parameters in that step (the one with ?q=Microsoft

 

Please let me know if it still works.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.