Skip to content

Instantly share code, notes, and snippets.

@u110
Last active May 7, 2019 14:42
Show Gist options
  • Save u110/9f153371ae2e52beb5e93575de6fc820 to your computer and use it in GitHub Desktop.
Save u110/9f153371ae2e52beb5e93575de6fc820 to your computer and use it in GitHub Desktop.
import requests
OAUTH_ACCESS_TOKEN = "xoxp-21*****"
def fetch_image(url):
headers = {
"Authorization": "Bearer %s" % OAUTH_ACCESS_TOKEN
}
res = requests.get(url, headers=headers)
print(res.status_code)
# print(res.headers['content-type'])
if res.status_code != 200:
print(res)
raise ValueError("Download failed. url: %s" % url)
return res.content
if __name__ == "__main__":
url = "https://files.slack.com/files-pri/****/shared_image.jpg"
image_data = fetch_image(url)
filename = url.split("/")[-1]
with open(filename, "wb") as f:
f.write(image_data)
@u110
Copy link
Author

u110 commented May 7, 2019

https://api.slack.com/tutorials/working-with-files

  • botの file:read
  • HTTP GET
  • header: Authorization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment