'how to change refresh.txt for Bing Ads refresh token rather than default location same with refresh token python script
Follows this official guideline, https://docs.microsoft.com/en-us/advertising/guides/walkthrough-desktop-application-python?view=bingads-13, I received the refresh token successfully and was able to make the first API. Now I would like to open and save refresh token from the different path rather than the default location of the python script .
Here is what I tried. For example, from the above python script, the REFRESH_TOKEN was initiated by default as the same location with my python script. I have tried REFRESH_TOKEN = different_file_path + "refresh.txt" to initiate the different path, but the new refresh token was not generated. If I reverted back to default file path, I could received the new refresh token.
So how would I change the file path so that this python would open and save the new refresh token to my preferred location?
-- The original python script:
# REFRESH_TOKEN = different_file_path + "refresh.txt" # Tried but couldn't get the new refresh token
REFRESH_TOKEN="refresh.txt"
def save_refresh_token(oauth_tokens):
'''
Stores a refresh token locally. Be sure to save your refresh token securely.
'''
with open(REFRESH_TOKEN,"w+") as file:
file.write(oauth_tokens.refresh_token)
file.close()
return None
Solution 1:[1]
Later I found a guideline how to change the file path of the refresh.txt in Java:
The refresh token will be written to refresh.txt. Subsequent calls to the authenticateWithOAuth helper function will attempt to read the refresh token from the same location. You can change the location by editing the RefreshTokenPath setting within ExampleBase.java.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jade Nguyen |
