Created
March 10, 2018 14:26
-
-
Save BlaayLock/a6e30ba9bbdd08975ba24263c67996e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python.exe | |
# coding=utf-8 | |
# vim: set fileencoding=utf-8 : | |
#~ print "Content-Type: text/html\r\n" | |
''' | |
надо | |
Установка статуса (SET_STATUS) | |
Изменение фотографий и фотоальбомов (PHOTO_CONTENT) | |
Доступ к основной информации (VALUABLE_ACCESS) | |
Доступ к группам (GROUP_CONTENT) | |
Application ID: 1246165776. | |
Публичный ключ приложения: CBAHLMELSFRBABABA. | |
Секретный ключ приложения: 50852A4DD512734A9BAE66A4. | |
Ссылка на приложение: http://www.odnoklassniki.ru/game/1246165776 | |
''' | |
import hashlib | |
import json,requests | |
try: | |
from urllib import quote # Python 2.X | |
except ImportError: | |
from urllib.parse import quote # Python 3+ | |
import odnoklassniki | |
ok = odnoklassniki.Odnoklassniki('CBAHLMELSFRBABABA', '50852A4DD512734A9BAE66A4', 'tkn1gj3nXJNLv2E3xEmadsf4331feiDqNvVf9lypNpzTfxmBaDsd4ev4dVRmV7E4nGiCFT') | |
#~ ok.group.getInfo('uids'='54791230327999') | |
#~ print ok.group.getInfo(uids='54791230327999', fields="UID,CITY") #~ https://apiok.ru/dev/methods/rest/group/group.getInfo | |
photo_to_post_wall='e8399b09-1a0a-4b26-a00b-83a1ec2c9d5b.gif' | |
title_to_post_wall='TITLE send by OK API , test test auto post' | |
text_to_post_wall='TEXT send by OK API , test test auto post' | |
url_to_post_wall='http://ya.ru' | |
ok_client_public='CBAHLMELSFRBABABA' | |
ok_group_id='54791230327999' | |
ok_client_secret='50852A4DD512734A9BAE66A4' | |
ok_access_token='tkn1gj3nXJNLv2E3xEmadsf4331feiDqNvVf9lypNpzTfxmBaDsd4ev4dVRmV7E4nGiCFT' | |
secret_key = hashlib.md5((ok_access_token + ok_client_secret).encode('utf-8')).hexdigest() | |
api_server = 'https://api.ok.ru/fb.do?' | |
sig = hashlib.md5(( | |
'application_key=' + ok_client_public + | |
'format=json' | |
'gid=' + ok_group_id + | |
'method=photosV2.getUploadUrl' + | |
secret_key | |
).encode('utf-8')).hexdigest() | |
upload_url = requests.get( | |
api_server + | |
'&application_key=' + ok_client_public + | |
'&format=json' | |
'&gid=' + ok_group_id + | |
'&method=photosV2.getUploadUrl' + | |
'&sig=' + sig + | |
'&access_token=' + ok_access_token | |
).json() | |
image=photo_to_post_wall | |
file_ = {'photo': (image, open(image, 'rb'))} | |
post_image = requests.post(upload_url['upload_url'], files=file_).json() | |
token = post_image['photos'][upload_url['photo_ids'][0]]['token'] | |
#~ print token | |
ok_attachment = {'media': [ | |
{ | |
"type": "text", | |
"text": title_to_post_wall | |
}, | |
{ | |
"type": "photo", | |
"list": [ | |
{"id": token} | |
] | |
}, | |
{ | |
"type": "link", | |
"url": url_to_post_wall | |
}, | |
{ | |
"type": "text", | |
"text": text_to_post_wall | |
} | |
], | |
"onBehalfOfGroup": "true","disableComments": "false" | |
} | |
sig = hashlib.md5(( | |
'application_key=' + ok_client_public + | |
'attachment=' + str(json.dumps(ok_attachment)) + | |
'format=json' | |
'gid=' + ok_group_id + | |
'method=mediatopic.post' | |
'type=GROUP_THEME' + | |
secret_key | |
).encode('utf-8')).hexdigest() | |
mediatopic_post = requests.get( | |
api_server + | |
'application_key=' + ok_client_public + | |
'&attachment=' + quote(str(json.dumps(ok_attachment))) + | |
'&format=json' | |
'&gid=' + ok_group_id + | |
'&method=mediatopic.post' | |
'&type=GROUP_THEME' | |
'&sig=' + sig + | |
'&access_token=' + ok_access_token | |
).json() | |
print mediatopic_post | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment