step1=ok_api.photosV2.getUploadUrl(gid='53190520930516'
,aid='53229159252180'
,count=1)
print step1
print 'step1 done ...I obtain this: (see 2 rows below)'
# {u'upload_url': u'https://gup.mycdn.me/uploadImage?apiToken=Vml3G1rxjH5x%2BQ0Fo9GTPjRQ%2F19vVAS7ajrzE0CeAZwVxvua92aUlvzQRCOUYywWiYo6QmXE1kEb1karWi0T8iph0dapGJd8PwYyoKm7FyNdzQ5mPA5MMvZIMhtGpdQtv9tyVi1phB4%3D&photoIds=k4feX2Y0EkMKBQi1L7sdL6HShvz2V90Yt5B%2BPk1xBquA0NzkgT7XrA%3D%3D',
#u'expires': u'2016.11.13 21:22', u'expires_ms': 1479061358474L, u'photo_ids': [u'k4feX2Y0EkMKBQi1L7sdL6HShvz2V90Yt5B+Pk1xBquA0NzkgT7XrA==']}
print '.. now I unquote the apitoken that is in the upload_url that is returned..'
wsplit=step1['upload_url'].split('apiToken=')
wsplit2=wsplit[1].split('&photoIds=')
wapitoken_to_unquote = wsplit2[0]
wapitoken_unquoted = urllib.unquote(wapitoken_to_unquote)
print '.. and this is the token to use in commit..'
print wapitoken_unquoted
print '.. and now upload the image..'
r = requests.post(step1['upload_url'], files={'testupload.jpg': open('testupload.jpg', 'rb')})
print r
print'..I obtain <Response [200]> so is ok...'
print '.. I try the commit...'
stoken = wapitoken_unquoted
step3=ok_api.photosV2.commit(photo_id=step1['photo_ids'][0]
,comment='some text about the image...'
,token=stoken)
print ' ..and I obtain a message like this -> UNKNOWN : Unexpected error, logged by ID : APIERR1478682114969_93'
import pyodnoklassniki
pyodnoklassniki.app_pub_key = 'app_pub_key '
pyodnoklassniki.app_secret_key = 'app_secret_key '
self.ok_api_Auth = pyodnoklassniki.OdnoklassnikiAPI(access_token='access_token', session_secret_key='session_secret_key')
photos = self.ok_api_Auth.photosV2.getUploadUrl(permissions='VALUABLE_ACCESS;LONG_ACCESS_TOKEN;GROUP_CONTENT;PHOTO_CONTENT',format = 'json',gid = 'group_id', count = 2)
#print (photos)
#print (photos['photo_ids'][0])
filename1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'repost') + '/1.jpg'
filename2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'repost') + '/2.jpg'
r = requests.post(str(photos['upload_url']), files={'1.jpg': open(filename1, 'rb'),'2.jpg': open(filename2, 'rb')}).json()
attachment = '{"media": [{' \
'"type": "photo", ' \
'"list": [' \
'{ "id": "' + str(r['photos'][str(photos['photo_ids'][0])]['token'])+ '" },' \
'{ "id": "' + str(r['photos'][str(photos['photo_ids'][1])]['token'])+ '" }' \
']},' \
'{"type": "link",' \
'"url": "' + str('http://ya.ru') + '"},' \
'{"type": "text",' \
'"text": "' + str('hello') + '"}' \
']}'
rgroups = self.ok_api_Auth.mediatopic.post(permissions='VALUABLE_ACCESS;LONG_ACCESS_TOKEN;GROUP_CONTENT;PHOTO_CONTENT',format = 'json', attachment=attachment, type='GROUP_THEME', gid='group_id')