【问题标题】:Missing client_id or access_token URL parameter. (InstagramApi::BadRequest)缺少 client_id 或 access_token URL 参数。 (InstagramApi::BadRequest)
【发布时间】:2023-03-03 11:13:01
【问题描述】:

我的代码返回 InstagramApi::BadRequest 我的客户 ID 并访问他的令牌,一切正常!我通过网站和正常流程生成令牌!

require 'instagram_api_client'
require 'dotenv'

Dotenv.load
def login_insta

    client.new = InstagramApi.config do |config|
        config.access_token = ENV["INSTA_ACCESS_TOKEN"]
        config.client_id = ENV["INSTA_CLIENT_ID"]
        config.client_secret = ENV["INSTA_CLIENT_SECRET"]
    end
    return client
end

def auto_follow_test
    #ary = Array.new

      search_user = InstagramApi.user.search('75')

    #ary << search


   # puts ary[0]
   return search_user
end

auto_follow_test

Traceback (most recent call last):
        4: from lib/app.rb:28:in `<main>'
        3: from lib/app.rb:19:in `auto_follow_test'
        2: from /home/mhd/.rvm/gems/ruby-2.5.1/gems/instagram_api_client-0.2.1/lib/instagram_api/common.rb:10:in `search'
        1: from /home/mhd/.rvm/gems/ruby-2.5.1/gems/instagram_api_client-0.2.1/lib/instagram_api/client.rb:37:in `make_request'
/home/mhd/.rvm/gems/ruby-2.5.1/gems/instagram_api_client-0.2.1/lib/instagram_api/client.rb:53:in `parse_failed': Missing client_id or access_token URL parameter. (InstagramApi::BadRequest)

【问题讨论】:

  • 开头的client.new = 是什么?没有一个文档有这样的代码;您需要配置 InstagramApi 然后拨打所有电话。你确定你做这部分正确吗?您是否已验证其配置正确?
  • 我现在只放客户端的错误
  • 我不知道那是什么意思。
  • 我只是写了一个没有任何变量的变量。新的
  • 为什么? config 似乎本质上是一个静态初始化程序。无论如何,您没有提供任何进一步的有用信息。

标签: ruby api rubygems access-token instagram-api


【解决方案1】:

您的代码示例有点乱:

  1. 您定义了一个方法 login_insta 来配置您的凭据,但您从不调用该方法来运行配置。

  2. 如果您确实调用了login_insta,它仍然无法正常工作,因为调用了client.new,这在您的代码示例中没有解释,并且违反了the instructions from the gem author 关于如何配置凭据的规定。

在这种情况下,将您的代码减少到 minimal, complete, verifiable example 可能会解决问题:

require 'instagram_api_client'
require 'dotenv'

Dotenv.load

# Set the global configuration for the gem per the instructions at:
# https://github.com/agilie/instagram_api_gem#usage
InstagramApi.config do |config|
  config.access_token = ENV["INSTA_ACCESS_TOKEN"]
  config.client_id = ENV["INSTA_CLIENT_ID"]
  config.client_secret = ENV["INSTA_CLIENT_SECRET"]
end

InstagramApi.user.search('75')

我无法独立验证这是否解决了问题,因为我没有 Instagram API 访问权限,但鉴于 gem 的自述文件中的说明,这应该是解决方案。

当您将此解决方案合并到您的代码中时,只需确保对InstagramApi.config 的调用仅在您进行任何 API 调用之前运行一次。它不需要包装在方法调用中。 (不应该,因为它只需要运行一次,运行一次后它将在 Ruby 进程的整个生命周期内保持有效)

【讨论】:

  • 谢谢 有一个新错误:此客户未获准访问此资源。 (InstagramApi::BadRequest)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
  • 2012-04-30
  • 1970-01-01
  • 1970-01-01
  • 2014-05-31
  • 2017-01-15
  • 2012-08-29
相关资源
最近更新 更多