有什么方法可以在不使用 instagram API 的情况下获取 instagram 用户 _ID?
Is there any way of getting instagram User _ID without using the instagram API?
我的任务不是生成任何应用程序或网站,而只是编写一个 PYTHON 脚本,将用户名作为输入并检索用户 ID 作为结果。
因为 instagram 要求应用程序名称、网站、URI 和所有其他东西以便能够接收客户端 ID 和其他东西以便能够使用他们的 API 而我没有应用程序作为这样,我没有资格。
那么,如果没有 Instagram API,我们有什么办法可以做到吗?
如果没有别的办法,怎么办?
我也是 python 编程和与 API 连接的新手。如果有人能帮我提供代码,那将非常有帮助。
谢谢!
好吧,问题的答案是我们可以使用 Instagram API 本身。正如@Selcuk 所说,我们可以在 Instagram 网站上使用占位符进行注册。那么我们将从中获取 client_id 和 client_secret,如果我们是注册的 instagram 用户,我们也会获取访问令牌。
访问令牌如果很难找到,可以通过https://apigee.com/console/instagram获得
然后在顶部的身份验证选项中,select OAuth 将带您进入 instagram 的登录页面。发送查询后,它会显示您发出的请求,也可以找到访问令牌。
在 python 控制台中输入:-
import urllib.request
import urllib.parse
from instagram.client import InstagramAPI
access_token="YOUR ACCESS TOKEN&q"
api=InstagramAPI(client_id= 'YOUR CLIENT ID', client_secret='YOUR CLIENT SECRET')
scope='public_content'
url='https://api.instagram.com/v1/users/search?q=USERNAME TO SEARCH&access_token=YOUR ACCESS TOKEN'
a=urllib.request.urlopen(url)
print(a.read())
这将为您提供有关用户的详细信息。
我将此代码放在下面 (python 3.5.2) 仅使用 urllib
并且它像梦一样工作!
from six.moves.urllib.request import urlopen
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
id_loop = True
while id_loop == True:
username = input('Please enter the Instagram username that you would like to find the User ID for: ')
link = 'http://www.instagram.com/' + username
response = urlopen(link)
content = str(response.read());
start_index = (content.index('"owner": {"id": "')) + len('"owner": {"id": "')
test_string = ''
for collect in range(14):
test_string = test_string + content[start_index]
start_index = start_index + 1
edit_string = ''
for char in test_string:
if is_number(char) == True:
edit_string = edit_string + char
else:
edit_string = edit_string + ''
print(username + "'s Instagram ID = " + edit_string)
如您所见,您唯一需要的模块是 urllib。此代码实质上是找到您输入的用户名的 Instagram 页面,并将变量 content
设置为等于由网页的整个 html 代码组成的单个字符串。然后通过代码搜索此字符串以查找用户的 Instagram ID。希望这对您有所帮助!
猜测代码中的内容会发生变化,但生活中的挑战依然存在...
我们开始吧...一些简洁的 python 代码让事情变得更简单!
python函数用户名到id
from six.moves.urllib.request import urlopen
def get_insta_id(username):
link = 'http://www.instagram.com/' + username
response = urlopen(link)
content = str(response.read())
start_pos = content.find('"owner":{"id":"') + len('"owner":{"id":"')
end_pos = content[start_pos:].find('"')
insta_id = content[start_pos:start_pos+end_pos]
return insta_id
print(get_insta_id("username"))
我的任务不是生成任何应用程序或网站,而只是编写一个 PYTHON 脚本,将用户名作为输入并检索用户 ID 作为结果。
因为 instagram 要求应用程序名称、网站、URI 和所有其他东西以便能够接收客户端 ID 和其他东西以便能够使用他们的 API 而我没有应用程序作为这样,我没有资格。 那么,如果没有 Instagram API,我们有什么办法可以做到吗?
如果没有别的办法,怎么办?
我也是 python 编程和与 API 连接的新手。如果有人能帮我提供代码,那将非常有帮助。
谢谢!
好吧,问题的答案是我们可以使用 Instagram API 本身。正如@Selcuk 所说,我们可以在 Instagram 网站上使用占位符进行注册。那么我们将从中获取 client_id 和 client_secret,如果我们是注册的 instagram 用户,我们也会获取访问令牌。
访问令牌如果很难找到,可以通过https://apigee.com/console/instagram获得 然后在顶部的身份验证选项中,select OAuth 将带您进入 instagram 的登录页面。发送查询后,它会显示您发出的请求,也可以找到访问令牌。
在 python 控制台中输入:-
import urllib.request
import urllib.parse
from instagram.client import InstagramAPI
access_token="YOUR ACCESS TOKEN&q"
api=InstagramAPI(client_id= 'YOUR CLIENT ID', client_secret='YOUR CLIENT SECRET')
scope='public_content'
url='https://api.instagram.com/v1/users/search?q=USERNAME TO SEARCH&access_token=YOUR ACCESS TOKEN'
a=urllib.request.urlopen(url)
print(a.read())
这将为您提供有关用户的详细信息。
我将此代码放在下面 (python 3.5.2) 仅使用 urllib
并且它像梦一样工作!
from six.moves.urllib.request import urlopen
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
id_loop = True
while id_loop == True:
username = input('Please enter the Instagram username that you would like to find the User ID for: ')
link = 'http://www.instagram.com/' + username
response = urlopen(link)
content = str(response.read());
start_index = (content.index('"owner": {"id": "')) + len('"owner": {"id": "')
test_string = ''
for collect in range(14):
test_string = test_string + content[start_index]
start_index = start_index + 1
edit_string = ''
for char in test_string:
if is_number(char) == True:
edit_string = edit_string + char
else:
edit_string = edit_string + ''
print(username + "'s Instagram ID = " + edit_string)
如您所见,您唯一需要的模块是 urllib。此代码实质上是找到您输入的用户名的 Instagram 页面,并将变量 content
设置为等于由网页的整个 html 代码组成的单个字符串。然后通过代码搜索此字符串以查找用户的 Instagram ID。希望这对您有所帮助!
猜测代码中的内容会发生变化,但生活中的挑战依然存在... 我们开始吧...一些简洁的 python 代码让事情变得更简单!
python函数用户名到id
from six.moves.urllib.request import urlopen
def get_insta_id(username):
link = 'http://www.instagram.com/' + username
response = urlopen(link)
content = str(response.read())
start_pos = content.find('"owner":{"id":"') + len('"owner":{"id":"')
end_pos = content[start_pos:].find('"')
insta_id = content[start_pos:start_pos+end_pos]
return insta_id
print(get_insta_id("username"))