Answer the question
In order to leave comments, you need to log in
How to implement VK API requests via Python without a token?
I have this: https://habrahabr.ru/sandbox/84639/
There, the request is made through vkapi.method, and I need to implement token-free requests without authorization. How to do it? Tried just import vk, vk.method - doesn't work.
Here's what to do now:
import urllib2, json, os.path
DIR = os.path.abspath(os.curdir) + '/'
def get(url, timeout=10):
try:
res = urllib2.urlopen(url, timeout=timeout).read()
except:
print 'get error'
res = 0
return res
def json_convert(string):
return json.loads(string)
def groups_getById(group_ids=None, group_id=None, fields=None):
url = 'https://api.vk.com/method/groups.getById?group_ids=' + str(group_ids) + '&group_id=' + str(group_id) + '&fields=' + str(fields)
return json_convert(get(url))
def groups_getMembers(group_id=None, sort=None, offset=None, count=None, fields=None, filter=None):
url = 'https://api.vk.com/method/groups.getById?&group_id=' + str(group_id) + '&sort=' + str(sort) + '&offset=' + str(offset) + '&count=' + str(count) + '&fields=' + str(fields) + '&filter=' + str(filter)
return json_convert(get(url))
Answer the question
In order to leave comments, you need to log in
Close the article attached to the question and never read it. Install the Requests
library and use it to make requests.
The list of methods is on vk.com/dev/methods
Hello.
I recommend using the library https://github.com/prawn-cake/vk-requests
import vk_requests
api = vk_requests.create_api()
api.users.get(user_ids=1)
[{'first_name': 'Pavel', 'last_name': 'Durov', 'id': 1}]
import urllib
import urllib2, json, os.path
class Api():
main_url = 'https://api.vk.com/method/'
def method(self, method, params=None):
if not params:
params = {}
full_url = self.generate_url(method, params)
return urllib2.urlopen(full_url, timeout=timeout).read()
def generate_url(self, method, params):
m = self.main_url + method + "?" +urllib.urlencode(params)
return m
api = Api()
res = api.method('users.get', {"user_ids" : 1, 'fields': "photo_50,city,verified"})
Maybe you should try making requests directly. Can you handle networking and JSON parsing? I'm sure there are plenty of ready-made high-level solutions for this.
Found this: Vk api python without acess_token? But is there an option? I do not want to write all the functions again in python via urllib.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question