【问题标题】:facebook bot Failed to fetch the file from the urlfacebook bot 无法从 url 获取文件
【发布时间】:2016-11-22 12:48:57
【问题描述】:

我的 facebook 机器人有 2200 个订阅者,所以我使用下面的代码每天给他们发送一张图片。但是,对于大多数用户来说,这段代码都失败了,因为从 bot 框架中捕获了错误

 public static class MessagesSender
{
    public static void SendSpecificMessage(string botName, string serviceURL, string botId, string messageCode, string messageText, string imageURL, Customer customer , Guid logId)
    { 
        var connector = new ConnectorClient(new Uri(serviceURL)); 

        Thread thread = new Thread(() => SendMessage(botName, serviceURL, botId, messageCode, messageText, imageURL, customer, connector , logId));
        thread.Start(); 

    }

    private static void SendMessage(string botName, string serviceURL, string botId, string messageCode, string messageText, string imageURL, Customer customer, ConnectorClient connector , Guid logId)
    {


        try
        {


        Task.Run(async () =>
        {
            IMessageActivity message = Activity.CreateMessageActivity();
            //defining accounts 
            var userAccount = new ChannelAccount(name: customer.name, id: customer.fromidstate);
            var botAccount = new ChannelAccount(name: botName, id: botId);

            //creating conversation
            var conversationId =  await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);


            message.From = botAccount;
            message.Recipient = userAccount;



            message.Text = "Daily Image";
            message.Conversation = new ConversationAccount(id: conversationId.Id.Replace("@", string.Empty));



            if (!string.IsNullOrEmpty(imageURL))
            {
                message.Attachments = new List<Attachment>();
                message.Attachments.Add(new Attachment()
                {
                    ContentUrl = imageURL,
                    ContentType = "image"
                });
            }




            await connector.Conversations.SendToConversationAsync((Activity)message);



        }).Wait();
        }
        catch ( Exception ex)
        {
            throw ex;

        } 
    }
}

{"error":{"message":"(#100) Failed to fetch the file from the url","type":"OAuthException","code":100,"error_subcode":2018008,"fbtrace_id":"G8ZFKZLCmNp"}}

我不知道该怎么做,因为当我发送一条消息时,它工作正常,但并非所有 2200 条消息都没有发送,如果我发送给 10 人就可以了。而且主要的问题是文本被传递而不是图像

【问题讨论】:

  • 我从 url 'developers.facebook.com/docs/messenger-platform/…' 中的示例中获取了内容类型,是的,它是公共图像,此代码也适用于少数用户发送,它只是不适用于数千个用户
  • 返回给您的错误是由 Facebook API 返回的。当附件不是有效的 URL 时,Facebook 通常会返回此错误。您确定要向所有用户发送完全相同的内容吗?
  • 是的,我通过减慢发送过程解决了这个问题,我没有创建 2200 个线程,而是每秒创建 10 个线程,虽然我不确定这是否会成为问题,但现在一切都很好

标签: botframework


【解决方案1】:

Facebook API 正在返回错误。看起来您正在达到节流限制。解决方案是减慢发送图像的速度。

如需确认,可查看错误返回码(“613”)

Facebook error codes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    相关资源
    最近更新 更多