Telegram Bot API 方法 (getUserProfilePhotos)
Telegram Bot API method (getUserProfilePhotos)
我正在为 NodeJS https://github.com/yagop/node-telegram-bot-api 使用这个 Telegram Bot API 并且有一个方法 "getUserProfilePhotos",我使用它并得到错误:
"Bad Request: there is no photo in the request"
这是我的代码
var TelegramBot = require('node-telegram-bot-api');
var token = '********************************************';
var bot = new TelegramBot(token, {polling: true});
bot.on('message', function (msg) {
var chatId = msg.chat.id;
var userId = msg.from.id;
bot.sendMessage(chatId,"There is something");
bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 1, 1) ,{caption: "It's your photo!"});
});
我的电报帐户中有一张个人资料照片。我不知道该怎么办。有人能帮我吗?对不起我的工程师)
试试这个,正常工作:
bot.onText(/\/testuserphoto$/, function onMessage(msg) {
var chatId = msg.chat.id;
var userId = msg.from.id;
bot.getUserProfilePhotos(userId, 0, 1).then(function(data){
bot.sendPhoto(chatId,data.photos[0][0].file_id,{caption: "It's your photo!"});
});
});
getUserProfilePhoto returns an UserProfilePhotos 和 photos 属性包含用户个人资料列表。除了 getUserProfilePhoto 方法之外,第二个参数是照片 ID 而不是照片对象。
数组基索引号为 0
但是你用的是1和1!在这一行中:
bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 1, 1) ,{caption: "It's your photo!"});
更正为:
bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 0, 0) ,{caption: "It's your photo!"});
我正在为 NodeJS https://github.com/yagop/node-telegram-bot-api 使用这个 Telegram Bot API 并且有一个方法 "getUserProfilePhotos",我使用它并得到错误:
"Bad Request: there is no photo in the request"
这是我的代码
var TelegramBot = require('node-telegram-bot-api');
var token = '********************************************';
var bot = new TelegramBot(token, {polling: true});
bot.on('message', function (msg) {
var chatId = msg.chat.id;
var userId = msg.from.id;
bot.sendMessage(chatId,"There is something");
bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 1, 1) ,{caption: "It's your photo!"});
});
我的电报帐户中有一张个人资料照片。我不知道该怎么办。有人能帮我吗?对不起我的工程师)
试试这个,正常工作:
bot.onText(/\/testuserphoto$/, function onMessage(msg) {
var chatId = msg.chat.id;
var userId = msg.from.id;
bot.getUserProfilePhotos(userId, 0, 1).then(function(data){
bot.sendPhoto(chatId,data.photos[0][0].file_id,{caption: "It's your photo!"});
});
});
getUserProfilePhoto returns an UserProfilePhotos 和 photos 属性包含用户个人资料列表。除了 getUserProfilePhoto 方法之外,第二个参数是照片 ID 而不是照片对象。
数组基索引号为 0
但是你用的是1和1!在这一行中:
bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 1, 1) ,{caption: "It's your photo!"});
更正为:
bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 0, 0) ,{caption: "It's your photo!"});