title: Saving login token as json in local project file
body: <p><strong>Background</strong></p>
  <p>I am trying to make python-based app login system through API provided by Kakao corporation, so that I can renew my refresh token to continue using my app. <a href="https://developers.kakao.com/docs/latest/en/kakaologin/common" rel="nofollow noreferrer">Documentation</a> says refresh token expires within 2 months, so this python file will allow me to renew the refresh token simply clicking a button.</p>
  <p>Here is the <strong>summarized process</strong>:</p>
  <ol>
  <li>Click login button using PyQt5. When clicked, This button will request a url containing rest API key and redirect uri as a parameter, using GET method.</li>
  <li>Response from 1.) contains login url for users to login with Kakao account.</li>
  <li>Whenever I log in from 2.), login url redirects to redirect_uri containing a code attached as a query string. For example, if redirect uri is <code>http://127.0.0.1:5000/oauth</code>, then it would look like this: <code>http://127.0.0.1:5000/oauth?code=D-4C0qgYH_XlVabXcVMB-AQEEL3wgm7D6xv3jwo9dJkAAAF8ncZ4BQ</code></li>
  <li>Save this code as python variable.</li>
  <li>Requesting url (posted in documentation) and this code as parameter using POST method gives back an access token and refresh token that will allow users to access my app.</li>
  </ol>
  <p><strong>Problem</strong></p>
  <p>The problem I am having is at step 4. I am stuck finding a way to pass url parameter to python file. The code parameter only appears after successful login, so is there any clever way to get parameters of a redirected webpage?</p>
  <p><strong>Code</strong></p>
  <pre><code>import sys
  from PyQt5.QtWidgets import *
  from PyQt5.QtGui import *
  from PyQt5.QtCore import *
  from pythonProject.send_message import *
  import webbrowser
  import requests
  
  
  class MyApp(QWidget):
  
      def __init__(self):
          super().__init__()
          self.initUI()
  
  
      def initUI(self):
          btn3 = QPushButton('Open Login Page', self)
          btn3.move(80, 93)
          btn3.clicked.connect(self.btn3_clicked)
          self.show()
  
  
      def btn3_clicked(self):
          # URL containing rest api key (= client_id) and redirect uri
          REST_API_KEY = &quot;6f86b2c435a386a703385dccb678aa7d&quot;
          REDIRECT_URI = &quot;https://...&quot;  # my app url
          url = f&quot;https://kauth.kakao.com/oauth/authorize?client_id={REST_API_KEY}&amp;&quot; \
                f&quot;redirect_uri={REDIRECT_URI}&amp;response_type=code&quot;
  
          login_url = requests.get(url).url  # URL for users to login with their account
  
          webbrowser.open(login_url) # Opens login page
  
  
          # Do something here to get code from redirect_uri
  
          code = &quot;________________________&quot;
  
  
          url_for_token = &quot;https://kauth.kakao.com/oauth/token&quot;  # Required URL to get access token
          data = {  # Required parameters
              &quot;grant_type&quot;: &quot;authorization_code&quot;,
              &quot;client_id&quot;: &quot;6f86b2c435a386a703385dccb678aa7d&quot;,  # Rest API key for my app
              &quot;redirect_uri&quot;: REDIRECT_URI,
              &quot;code&quot;: code
          }
          response = requests.post(url, data=data)
          tokens = response.json()
  
          print(tokens)
          # response.json() looks like this:
          #{
          # &quot;access_token&quot;: &quot;RTfiEkTXDznNc58PX5CpGbduj4XBL3AsZsCY7Ao9c5sAAAF8me74vg&quot;,
          # &quot;token_type&quot;: &quot;bearer&quot;,
          # &quot;refresh_token&quot;: &quot;AZuSOOBL6mVWq96_EiInMbNwrEGTho8pIAnYJAo9c5sAAAF8me74vA&quot;,
          # &quot;expires_in&quot;: 21599,
          # &quot;scope&quot;: &quot;talk_message profile_nickname friends&quot;,
          # &quot;refresh_token_expires_in&quot;: 5183999
          # }
  
          # Save token as json file
          with open(r&quot;C:\Users\admin\Desktop\project\bcmusic_private\pythonProject\kakao_authorization_code.json&quot;,
                    &quot;w&quot;) as fp:
              json.dump(tokens, fp)
  
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
      ex = MyApp()
      sys.exit(app.exec_())
  </code></pre>