|
@@ -0,0 +1,43 @@
|
|
1
|
+import requests
|
|
2
|
+import urllib
|
|
3
|
+import json
|
|
4
|
+
|
|
5
|
+def getAccessToken(refreshToken) :
|
|
6
|
+ url = "https://kauth.kakao.com/oauth/token"
|
|
7
|
+ payload = "grant_type=refresh_token&client_id=1fd8d72c840797ca81faeedb8abdfcfb&refresh_token=" + refreshToken
|
|
8
|
+ headers = {
|
|
9
|
+ 'Content-Type' : "application/x-www-form-urlencoded",
|
|
10
|
+ 'Cache-Control' : "no-cache",
|
|
11
|
+ }
|
|
12
|
+
|
|
13
|
+ reponse = requests.request("POST",url,data=payload, headers=headers)
|
|
14
|
+ access_token = json.loads(((reponse.text).encode('utf-8')))
|
|
15
|
+ return access_token
|
|
16
|
+
|
|
17
|
+def sendText(accessToken) :
|
|
18
|
+ url = 'https://kapi.kakao.com/v2/api/talk/memo/default/send'
|
|
19
|
+ payloadDict = dict({
|
|
20
|
+ "object_type" : "text",
|
|
21
|
+ "text" :"sample text",
|
|
22
|
+ "link" : {
|
|
23
|
+ "web_url" : "http://localhost:5000",
|
|
24
|
+ "mobile_web_url" : "http://localhost:5000.mobile"
|
|
25
|
+ },
|
|
26
|
+ "button_title" : "button-title",
|
|
27
|
+ })
|
|
28
|
+# payload = 'template_object=' + str(json.dumps(payloadDict))
|
|
29
|
+ payload = 'template_object=' + str(payloadDict)
|
|
30
|
+ print(payload)
|
|
31
|
+ headers = {
|
|
32
|
+ 'Content-Type' : "application/x-www-form-urlencoded",
|
|
33
|
+ 'Cache-Control' : "no-cache",
|
|
34
|
+ 'Authorization' : "Bearer " + accessToken,
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ reponse = requests.request("POST",url,data=payload, headers=headers)
|
|
38
|
+ access_token = json.loads(((reponse.text).encode('utf-8')))
|
|
39
|
+ return access_token
|
|
40
|
+
|
|
41
|
+result = getAccessToken("LZDlINbTkVDL-kiJoS_o0nyOPW25MqdhHQaBMgorDKcAAAFzHZWGXg") # 메세지 받을 사람의 REFRESH TOKEN 이용
|
|
42
|
+print(result['access_token'])
|
|
43
|
+print(sendText(result['access_token']))
|