[{"data":1,"prerenderedAt":379},["ShallowReactive",2],{"article-detail-x-data-source":3,"article-detail-localized-x-data-source-en":240},{"id":4,"title":5,"author":6,"body":11,"category":226,"date":229,"datetime":230,"description":231,"extension":232,"language":233,"meta":234,"navigation":135,"path":235,"seo":236,"stem":237,"translationKey":238,"__hash__":239},"articles/articles/x-data-source.md","Leveraging X (Twitter) as a Data Source for Research",{"name":7,"role":8,"href":9,"imageUrl":10},"Wilmer Gonzalez","AI Lead Engineer","/authors/wilmer-gonzalez","/wilmer-gonzalez.png",{"type":12,"value":13,"toc":218},"minimark",[14,19,23,27,50,54,109,113,177,181,207,211,214],[15,16,18],"h2",{"id":17},"introduction","Introduction",[20,21,22],"p",{},"X (formerly known as Twitter) is a powerful platform for collecting real-time data on public opinion, trends, and events. Its open API and vast user base make it an attractive source for researchers and analysts.",[15,24,26],{"id":25},"why-use-x-for-data-collection","Why Use X for Data Collection?",[28,29,30,38,44],"ul",{},[31,32,33,37],"li",{},[34,35,36],"strong",{},"Real-time insights:"," Access to live conversations and trending topics.",[31,39,40,43],{},[34,41,42],{},"Diverse data:"," Text, images, videos, and metadata.",[31,45,46,49],{},[34,47,48],{},"Public availability:"," Many posts are accessible via the API.",[15,51,53],{"id":52},"getting-started","Getting Started",[55,56,57,74,101],"ol",{},[31,58,59,62,65,66,73],{},[34,60,61],{},"Register for API Access:",[63,64],"br",{},"\nSign up for a developer account at ",[67,68,72],"a",{"href":69,"rel":70},"https://developer.x.com/",[71],"nofollow","developer.x.com"," and create a project to obtain API keys.",[31,75,76,79,81,82],{},[34,77,78],{},"Choose Your Tools:",[63,80],{},"\nPopular libraries include:",[28,83,84,95],{},[31,85,86,87,91,92],{},"Python: ",[88,89,90],"code",{},"tweepy",", ",[88,93,94],{},"snscrape",[31,96,97,98],{},"JavaScript: ",[88,99,100],{},"twitter-api-v2",[31,102,103,106,108],{},[34,104,105],{},"Define Your Query:",[63,107],{},"\nDecide on keywords, hashtags, or user handles relevant to your research.",[15,110,112],{"id":111},"example-collecting-tweets-with-python","Example: Collecting Tweets with Python",[114,115,120],"pre",{"className":116,"code":117,"language":118,"meta":119,"style":119},"language-python shiki shiki-themes github-light github-dark","import tweepy\n\nclient = tweepy.Client(bearer_token=\"YOUR_BEARER_TOKEN\")\n\nquery = \"data science -is:retweet lang:en\"\ntweets = client.search_recent_tweets(query=query, max_results=100)\n\nfor tweet in tweets.data:\n        print(tweet.text)\n","python","",[88,121,122,130,137,143,148,154,160,165,171],{"__ignoreMap":119},[123,124,127],"span",{"class":125,"line":126},"line",1,[123,128,129],{},"import tweepy\n",[123,131,133],{"class":125,"line":132},2,[123,134,136],{"emptyLinePlaceholder":135},true,"\n",[123,138,140],{"class":125,"line":139},3,[123,141,142],{},"client = tweepy.Client(bearer_token=\"YOUR_BEARER_TOKEN\")\n",[123,144,146],{"class":125,"line":145},4,[123,147,136],{"emptyLinePlaceholder":135},[123,149,151],{"class":125,"line":150},5,[123,152,153],{},"query = \"data science -is:retweet lang:en\"\n",[123,155,157],{"class":125,"line":156},6,[123,158,159],{},"tweets = client.search_recent_tweets(query=query, max_results=100)\n",[123,161,163],{"class":125,"line":162},7,[123,164,136],{"emptyLinePlaceholder":135},[123,166,168],{"class":125,"line":167},8,[123,169,170],{},"for tweet in tweets.data:\n",[123,172,174],{"class":125,"line":173},9,[123,175,176],{},"        print(tweet.text)\n",[15,178,180],{"id":179},"ethical-considerations","Ethical Considerations",[28,182,183,189,201],{},[31,184,185,188],{},[34,186,187],{},"Respect privacy:"," Only collect public data.",[31,190,191,194,195,200],{},[34,192,193],{},"Comply with X's terms:"," Review ",[67,196,199],{"href":197,"rel":198},"https://developer.x.com/en/developer-terms/agreement-and-policy",[71],"X's Developer Policy",".",[31,202,203,206],{},[34,204,205],{},"Anonymize data:"," Remove personal identifiers when sharing datasets.",[15,208,210],{"id":209},"conclusion","Conclusion",[20,212,213],{},"X is a valuable resource for data-driven projects. With the right tools and ethical practices, you can unlock insights from global conversations.",[215,216,217],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":119,"searchDepth":132,"depth":132,"links":219},[220,221,222,223,224,225],{"id":17,"depth":132,"text":18},{"id":25,"depth":132,"text":26},{"id":52,"depth":132,"text":53},{"id":111,"depth":132,"text":112},{"id":179,"depth":132,"text":180},{"id":209,"depth":132,"text":210},{"name":227,"href":228},"Data Collection","/categories/data-collection","2024-06-10","2024-06-10T09:00:00Z","Explore how to use the X (formerly Twitter) platform for effective data collection in research and analytics.","md","en",{},"/articles/x-data-source",{"title":5,"description":231},"articles/x-data-source","x-data-source","mrxudoUrLwCxuS4HGAlKu3J_1u8ILlAHkDZ3mDPFMDc",{"id":4,"title":5,"author":241,"body":242,"category":376,"date":229,"datetime":230,"description":231,"extension":232,"language":233,"meta":377,"navigation":135,"path":235,"seo":378,"stem":237,"translationKey":238,"__hash__":239},{"name":7,"role":8,"href":9,"imageUrl":10},{"type":12,"value":243,"toc":368},[244,246,248,250,264,266,301,303,343,345,362,364,366],[15,245,18],{"id":17},[20,247,22],{},[15,249,26],{"id":25},[28,251,252,256,260],{},[31,253,254,37],{},[34,255,36],{},[31,257,258,43],{},[34,259,42],{},[31,261,262,49],{},[34,263,48],{},[15,265,53],{"id":52},[55,267,268,277,295],{},[31,269,270,272,65,274,73],{},[34,271,61],{},[63,273],{},[67,275,72],{"href":69,"rel":276},[71],[31,278,279,281,81,283],{},[34,280,78],{},[63,282],{},[28,284,285,291],{},[31,286,86,287,91,289],{},[88,288,90],{},[88,290,94],{},[31,292,97,293],{},[88,294,100],{},[31,296,297,299,108],{},[34,298,105],{},[63,300],{},[15,302,112],{"id":111},[114,304,305],{"className":116,"code":117,"language":118,"meta":119,"style":119},[88,306,307,311,315,319,323,327,331,335,339],{"__ignoreMap":119},[123,308,309],{"class":125,"line":126},[123,310,129],{},[123,312,313],{"class":125,"line":132},[123,314,136],{"emptyLinePlaceholder":135},[123,316,317],{"class":125,"line":139},[123,318,142],{},[123,320,321],{"class":125,"line":145},[123,322,136],{"emptyLinePlaceholder":135},[123,324,325],{"class":125,"line":150},[123,326,153],{},[123,328,329],{"class":125,"line":156},[123,330,159],{},[123,332,333],{"class":125,"line":162},[123,334,136],{"emptyLinePlaceholder":135},[123,336,337],{"class":125,"line":167},[123,338,170],{},[123,340,341],{"class":125,"line":173},[123,342,176],{},[15,344,180],{"id":179},[28,346,347,351,358],{},[31,348,349,188],{},[34,350,187],{},[31,352,353,194,355,200],{},[34,354,193],{},[67,356,199],{"href":197,"rel":357},[71],[31,359,360,206],{},[34,361,205],{},[15,363,210],{"id":209},[20,365,213],{},[215,367,217],{},{"title":119,"searchDepth":132,"depth":132,"links":369},[370,371,372,373,374,375],{"id":17,"depth":132,"text":18},{"id":25,"depth":132,"text":26},{"id":52,"depth":132,"text":53},{"id":111,"depth":132,"text":112},{"id":179,"depth":132,"text":180},{"id":209,"depth":132,"text":210},{"name":227,"href":228},{},{"title":5,"description":231},1788757944169]