<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Paulo Montenegro Campos</title>
    <description>The latest articles on DEV Community by Paulo Montenegro Campos (@pmcampos).</description>
    <link>https://dev.to/pmcampos</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4260916%2F7746359f-65de-4ec6-8f4f-5587bdcbd769.jpg</url>
      <title>DEV Community: Paulo Montenegro Campos</title>
      <link>https://dev.to/pmcampos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pmcampos"/>
    <language>en</language>
    <item>
      <title>I Wanted Telegram Alerts for New Instagram Posts. Fetching a Profile with Python Was the Easy Part</title>
      <dc:creator>Paulo Montenegro Campos</dc:creator>
      <pubDate>Mon, 23 Nov 2026 15:35:05 +0000</pubDate>
      <link>https://dev.to/pmcampos/i-wanted-telegram-alerts-for-new-instagram-posts-fetching-a-profile-with-python-was-the-easy-part-3875</link>
      <guid>https://dev.to/pmcampos/i-wanted-telegram-alerts-for-new-instagram-posts-fetching-a-profile-with-python-was-the-easy-part-3875</guid>
      <description>&lt;p&gt;I wanted a simple Telegram bot that would notify me whenever certain Instagram accounts published something new.&lt;/p&gt;

&lt;p&gt;The idea was straightforward: check an account periodically, detect new posts, and send a Telegram notification.&lt;/p&gt;

&lt;p&gt;Before building the notification logic, I needed a reliable way to retrieve Instagram profile information. I started with Python and HikerAPI, and it took only a few lines of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Tried HikerAPI
&lt;/h2&gt;

&lt;p&gt;Initially, I was skeptical about using a third-party Instagram API. I've worked with scraping tools before, and they often require extra maintenance when websites change.&lt;/p&gt;

&lt;p&gt;I also didn't want to spend hours managing browser sessions or debugging login issues just to retrieve public profile data.&lt;/p&gt;

&lt;p&gt;That's when I came across &lt;a href="https://hikerapi.com/instagram-api-python?utm_source=devto&amp;amp;utm_medium=rewards" rel="noopener noreferrer"&gt;HikerAPI&lt;/a&gt;, a REST API for Instagram data.&lt;/p&gt;

&lt;p&gt;It advertises pricing starting at &lt;strong&gt;$0.001 per request&lt;/strong&gt;, with &lt;strong&gt;100 free requests&lt;/strong&gt; for testing.&lt;/p&gt;

&lt;p&gt;An API is preferable to scraping here because it avoids maintaining browser automation and HTML selectors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fetching an Instagram Profile with Python
&lt;/h2&gt;

&lt;p&gt;First, I installed the &lt;code&gt;requests&lt;/code&gt; library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, I created a Python script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"x-access-key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"YOUR_KEY"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"https://api.hikerapi.com/v2/user/by/username?username=nasa"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only setup needed is replacing &lt;code&gt;YOUR_KEY&lt;/code&gt; with an actual HikerAPI access key.&lt;/p&gt;

&lt;p&gt;Here's what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;x-access-key&lt;/code&gt; header authenticates the request.&lt;/li&gt;
&lt;li&gt;The endpoint looks up the Instagram profile &lt;code&gt;nasa&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;resp.json()&lt;/code&gt; converts the response into a Python dictionary.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;raise_for_status()&lt;/code&gt; catches unsuccessful HTTP responses.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's enough for a first test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting This to My Telegram Bot
&lt;/h2&gt;

&lt;p&gt;Retrieving a profile is only the first step. My bot also needs to check the account's latest posts.&lt;/p&gt;

&lt;p&gt;The intended workflow is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fetch the account's latest media using an appropriate API endpoint.&lt;/li&gt;
&lt;li&gt;Store the most recent post ID.&lt;/li&gt;
&lt;li&gt;Check periodically for a different ID.&lt;/li&gt;
&lt;li&gt;Send a Telegram message when a new post appears.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'd also persist the last processed ID so restarting the bot doesn't trigger duplicate notifications.&lt;/p&gt;

&lt;p&gt;One important consideration is request frequency. Even inexpensive API calls add up when monitoring multiple accounts, so choosing a reasonable polling interval matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;p&gt;The profile lookup was easier than I expected. A few lines of Python were enough to make an authenticated request and inspect Instagram profile data.&lt;/p&gt;

&lt;p&gt;That doesn't mean the entire bot is finished. I still need to implement media retrieval, state persistence, Telegram notifications, and error handling.&lt;/p&gt;

&lt;p&gt;But for a small personal automation project, starting with a REST API feels more practical than maintaining my own scraper.&lt;/p&gt;

&lt;p&gt;My takeaway: &lt;strong&gt;test the simplest API request first, then build the automation around what it actually returns.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>api</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
