- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to set Twitter OAuth attributes to InvokeHttp processor for fetching twitter user profiles
- Labels:
-
Apache NiFi
Created ‎04-11-2016 04:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use the InvokeHttp processor to fetch twitter user profiles from the url https://api.twitter.com/1.1/users/lookup.json?screen_name=twitterapi,twitter and my Nifi flow is GetFile(which sends screen_name, consumer_key, acess_token) -> updateAttribute(sets the mime.type) ->InvokeHttp(sets the url) -> PutFile. But i get the bad authentication data {"errors":[{"code":215,"message":"Bad Authentication data."}]}. How to set the oauth atrributes to the twitter url? Please help
Created ‎04-11-2016 07:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would recommend you the following links:
- https://dev.twitter.com/rest/reference/get/users/lookup
- https://dev.twitter.com/oauth/overview
With the first link, if you are connected on your Twitter account, you will see a part "OAuth Signature Generator" that will create for you all the HTTP header properties you must add in your request (as an example). You may also want to have a look to official documentation about OAuth (http://oauth.net/core/1.0a/) to understand how the properties are constructed.
Let me know if you still have issues.
Created ‎04-11-2016 07:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would recommend you the following links:
- https://dev.twitter.com/rest/reference/get/users/lookup
- https://dev.twitter.com/oauth/overview
With the first link, if you are connected on your Twitter account, you will see a part "OAuth Signature Generator" that will create for you all the HTTP header properties you must add in your request (as an example). You may also want to have a look to official documentation about OAuth (http://oauth.net/core/1.0a/) to understand how the properties are constructed.
Let me know if you still have issues.
Created ‎04-12-2016 02:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had a closer look on this, and I think your best option is to use an ExecuteScript processor to first create the parameter string, then the signature base string and, at the end, the Authorization string you need to set in the HTTP header properties of your InvokeHTTP processor.
Your flow would be something like:
GenerateFlowFile (to create an empty flow file) -> UpdateAttribute (to define all the parameters you need for OAuth) -> ExecuteScript (to compute the Authorization string) -> InvokeHTTP (with a custom property to set Authorization header property) -> PutFile (to get the result).
Regarding OAuth parameters, you will need to use Expression language for some parameters:
- timestamp with now() and subtring() to get seconds and not milliseconds.
- nonce can be generated using the UUID method
I wrote an article here to detail a solution where I use ExecuteScript processor and Groovy to perform the request you are looking for.
Created ‎04-12-2016 06:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Pierre Villard, Thank you so much for your help. The post is really useful. I imported your template, But How to execute it ? when i run the template with the keys and tokens defined in update attribute the execute script processor throws me an exception. Please find attached exception.screen-shot-2016-04-12-at-14210-pm.png Please let me know.
Created ‎04-12-2016 06:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My bad! I tried to clean the code and introduced an error... I updated the link to the template in the article and the gist as well (you can copy/paste the code from gist to the processor if you don't want to start over from the template). It should now be OK!
Created ‎04-14-2016 04:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Pierre Villard, i have a requirement, that i need to dynamically populate the screen_name in the url https://api.twitter.com/1.1/users/lookup.json?screen_name=twitterapi,twitter with the values from the hive table. Can you suggest me how can i implement with Nifi? Thanks.
Created ‎04-14-2016 05:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One option would be to get the content of your Hive table using a processor as the content of your FlowFile, then you could use an ExecuteScript processor to transform the content of your FlowFile as a string listing your usernames (screen_name=user1,user2,etc) and update the 'target' attribute as currently used at the begining of your current data flow.
Created ‎04-19-2016 06:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, as you suggested above, i got the content of the Hive table using FetchHDFS processor and sending the flowfile to a custom processor which needs to transform the flowfile content into a String listing of usernames. I am stuck here, how to loop thru the content of flowfile to fetch column1, column 3 eg SARAH ABDELSAYED) into a string listing for screen_name. I am using flowFile.getAttributes(), but could not see the log statements for the map. How to loop the content of flowfile to fetch specific columns. Thank you. My example flowfile content is attached.screenshot-7.png
Created ‎04-20-2016 09:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd suggest you to have a look at this post: http://funnifi.blogspot.co.uk/2016/02/executescript-processor-replacing-flow.html
It'll show you how to play around with the flow file content using ExecuteScript processor. Once you have your full string, you can put it as an attribute of the FlowFile or keep it as new content (it depends of what you have in mind).
Hope that helps.
Created ‎04-20-2016 03:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. I will look into that.
