Twitter API facilitates
Querying the twitter to know retweet etc
Posting to twitter via API
...
If you are using Twitter API first time, you need to perform setup in Twitter account. Also, you need to configure python modules to try out. Below document addresses this
Create python virtual environment and install python-twitter
$ pwd
/Users/deepak/Documents/coding/python$pip3 install virtualenv
$virtualenv neo4jenv
$source neo4jenv/bin/activate
(neo4jenv) Deepaks-MacBook-Air:python deepak$ pip3 install python-twitter
(neo4jenv) Deepaks-MacBook-Air:python deepak$ pip3 freeze
certifi==2019.11.28
chardet==3.0.4
future==0.18.2
idna==2.9
oauthlib==3.1.0
python-twitter==3.5
requests==2.23.0
requests-oauthlib==1.3.0
urllib3==1.25.8
(neo4jenv) Deepaks-MacBook-Air:python deepak$
Then perform the setup in your twitter account as mentioned at https://python-twitter.readthedocs.io/en/latest/getting_started.html
Then get the app secret info for your account and use in below code
Example to try out twitter API access
$ cat test.py -> It will list followings of the account
import twitter
api = twitter.Api(consumer_key='key',
consumer_secret='secret',
access_token_key='token',
access_token_secret='token_secret')
users = api.GetFriends()
print([u.screen_name for u in users])
$(neo4jenv) Deepaks-MacBook-Air:python
deepak$ python test.py
['friend1', 'friend2', 'kubernetesio']
To get list of tweets, refer code https://raw.githubusercontent.com/krdpk17/python-twitter/master/examples/get_all_user_tweets.py
Note that this output comes in JSON format
Example output for list of tweets
(neo4jenv) Deepaks-MacBook-Air:python deepak$ head examples/timeline.json
{"created_at": "Mon Mar 09 04:43:00 +0000 2020", "id": 1236875106757922817, "id_str": "1236875106757922817", "text": "99 + 1, that's me.", "truncated": false, "entities": {"hashtags": [], "symbols": [], "user_mentions": [], "urls": []}, "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>", "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "in_reply_to_screen_name": null, "user": {"id": 386798540, "id_str": "386798540", "name": "100", "screen_name": "100", "location": "", "description": "Life Academy.", "url": null, "entities": {"description": {"urls": []}}, "protected": false, "followers_count": 4353, "friends_count": 8, "listed_count": 139,....
Enable listening on Neo4j. For this, please refer steps mentioned at here
pip3 install neo4j is an example. There are more things to do. Please refer GitHub example here and documentation at here
pip3 install neo4j
(neo4jenv) Deepaks-MacBook-Air:python deepak$ pip3 install neo4j
Collecting neo4j
Downloading neo4j-1.7.6.tar.gz (23 kB)
Collecting neobolt~=1.7.15
Downloading neobolt-1.7.16.tar.gz (183 kB)
|████████████████████████████████| 183 kB 2.4 MB/s
Collecting neotime~=1.7.1
Downloading neotime-1.7.4.tar.gz (17 kB)
Collecting pytz
Downloading pytz-2019.3-py2.py3-none-any.whl (509 kB)
|████████████████████████████████| 509 kB 1.6 MB/s
Requirement already satisfied: six in ./neo4jenv/lib/python3.6/site-packages (from neotime~=1.7.1->neo4j) (1.14.0)
Building wheels for collected packages: neo4j, neobolt, neotime
Building wheel for neo4j (setup.py) ... done
Created wheel for neo4j: filename=neo4j-1.7.6-py3-none-any.whl size=32570 sha256=100803b683532546cd3c0643622e35c70d12febe4a589a1dfdea7c6ae15dfba9
Stored in directory: /Users/deepak/Library/Caches/pip/wheels/d7/1a/55/e3e4e254143635c20053f8f39301e1f58a79a07d75d6286c02
Building wheel for neobolt (setup.py) ... done
Created wheel for neobolt: filename=neobolt-1.7.16-py3-none-any.whl size=37138 sha256=445e9f676baa80d2d6974b1910dc20ffca6afaa2d44068de585ca4880a6fe9eb
Stored in directory: /Users/deepak/Library/Caches/pip/wheels/98/63/31/98f742c7a55528a7bd87e273b48dbfdebe4d19b9c2bd4f32da
Building wheel for neotime (setup.py) ... done
Created wheel for neotime: filename=neotime-1.7.4-py3-none-any.whl size=20541 sha256=8b618ed479a763430256f28f9d8c7b4ceafb833a75b097a3d339064087d78d14
Stored in directory: /Users/deepak/Library/Caches/pip/wheels/2f/a5/75/e4c94412ac76860c05f9042cfa656900f3635903dee6696629
Successfully built neo4j neobolt neotime
Installing collected packages: neobolt, pytz, neotime, neo4j
Successfully installed neo4j-1.7.6 neobolt-1.7.16 neotime-1.7.4 pytz-2019.3
Reference
https://python-twitter.readthedocs.io/en/latest/installation.html
https://github.com/krdpk17/python-twitter/tree/master/examples
https://opensourceconnections.com/blog/2013/11/27/quick-start-with-neo4j-using-your-twitter-data/
https://realpython.com/twitter-bot-python-tweepy/
https://sites.google.com/site/jbsakabffoi12449ujkn/home/digital-data-storage/understanding-cypher-query-of-neo4j#TOC-ORDER-BY-FOREACH-ON-CREATE-REPLACE-SPLIT
https://github.com/krdpk17/twitter-neo4j/blob/master/docker/import_user.py