Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获得;oauth访问机密“;用于连接到soundcloud api_Api_Oauth_Oauth Ruby_Soundcloud - Fatal编程技术网

如何获得;oauth访问机密“;用于连接到soundcloud api

如何获得;oauth访问机密“;用于连接到soundcloud api,api,oauth,oauth-ruby,soundcloud,Api,Oauth,Oauth Ruby,Soundcloud,我不熟悉使用网站的API。但很久以来,我一直想学习这一点,今天就从如何从soundcloud访问信息的简单示例开始。下面是他们的示例中简单示例的代码 我知道设置为什么: '您的\u应用程序\u消费者\u令牌' '您的应用程序\消费者\机密' 这是在soundcloud上注册应用程序时给出的 我将'YOUR_OAUTH_ACCESS_TOKEN'设置为 这也写在soundcloud网站上,但我不知道在哪里可以找到 \u您的OAUTH\u访问\u机密\u 这个访问秘密也是我从某处得到的一个随机字

我不熟悉使用网站的API。但很久以来,我一直想学习这一点,今天就从如何从soundcloud访问信息的简单示例开始。下面是他们的示例中简单示例的代码

我知道设置为什么:

  • '您的\u应用程序\u消费者\u令牌'
  • '您的应用程序\消费者\机密'
这是在soundcloud上注册应用程序时给出的

我将'YOUR_OAUTH_ACCESS_TOKEN'设置为 这也写在soundcloud网站上,但我不知道在哪里可以找到

\u您的OAUTH\u访问\u机密\u

这个访问秘密也是我从某处得到的一个随机字符串,我必须自己生成它吗


编辑正如精英先生们的回答中所建议的那样,我还尝试了Soundcloud认证示例。我在这里发布了一段已经导致错误的代码:

require 'rubygems'
gem 'soundcloud-ruby-api-wrapper'
require 'soundcloud'

# oAuth setup code:  
# Enter your consumer key and consumer secret values here:
@consumer_application = {:key => 'QrhxUWqgIswl8a9ESYw', :secret => 'tqsUGUD3PscK17G2KCQ4lRzilA2K5L5q2BFjArJzmjc'}

# Enter the path to your audio file here.  
path_to_audio_file = "your/absolute/path/to/audio_file.ext"

# Set up an oAuth consumer.  
@consumer = OAuth::Consumer.new @consumer_application[:key], @consumer_application[:secret], 
{
  :site               => 'http://api.sandbox-soundcloud.com', 
  :request_token_path => '/oauth/request_token',
  :access_token_path  => '/oauth/access_token',
  :authorize_path     => '/oauth/authorize'
}

# Obtain an oAuth request token
puts "Get request token"
request_token = @consumer.get_request_token
我收到的错误消息是:

OAuth::未授权:401未授权

位于的consumer.rb中的方法令牌\u请求 第217行方法获取\u请求\u令牌 顶部第139行的consumer.rb 第25行test1.rb中的电平


这个简单的示例怎么会失败?

与OAuth一样,如果希望最终用户通过应用程序访问Soundcloud的受保护资源,您必须向Soundcloud注册应用程序

当您使用OAuth从Soundcloud请求
access\u令牌时,它将返回您和
access\u令牌
以及
OAuth\u令牌
。您所说的
oauth\u令牌\u秘密
就是\u您的oauth\u访问权\u秘密

我不知道你对OAuth有多熟悉。可以找到文档


编辑OAuth授权方案不久前已更改(例如,获取访问令牌需要指定一个
OAuth\u验证器


请参阅使用最新的OAuth规范。

问题的答案非常简单。我的问题是我有 在soundcloud生产系统上注册我的应用程序 但是将我的请求指向了sandbox-soundcloud.com

我不得不去sandbox-soundcloud.com,注册一个新的用户帐户,然后做一个 新的客户端应用程序和一切工作都很完美

有关沙箱的更多信息,请访问:

谢谢您的快速回答。但我想你不明白我的问题是什么,可能是因为它太简单了。为了请求访问令牌(access\u token=OAuth::AccessToken.new(sc\u consumer,'YOUR\u OAuth\u access\u token','YOUR\u OAuth\u access\u SECRET')),我已经知道了YOUR\u OAuth\u access\u SECRET,你知道我的意思吗?@dedan,对于你的问题,答案是肯定的,但这似乎像是一个旧的OAuth身份验证方案。查看我编辑的文章以了解更多信息。好的,我将尝试您明天在编辑中发布的这个新示例。我只是想知道,因为我使用的那本书最后一次编辑是在2010年9月13日。非常感谢,我明天会在这里发布我的结果。我也尝试了你的建议(见我文章的编辑),但仍然不起作用。我怀疑这也可能是soundclous的问题!?我会尝试询问他们的用户群我不确定这些信息是否是最新的,但它已经开始向我解释一些秘密。
require 'rubygems'
gem 'soundcloud-ruby-api-wrapper'
require 'soundcloud'

# oAuth setup code:  
# Enter your consumer key and consumer secret values here:
@consumer_application = {:key => 'QrhxUWqgIswl8a9ESYw', :secret => 'tqsUGUD3PscK17G2KCQ4lRzilA2K5L5q2BFjArJzmjc'}

# Enter the path to your audio file here.  
path_to_audio_file = "your/absolute/path/to/audio_file.ext"

# Set up an oAuth consumer.  
@consumer = OAuth::Consumer.new @consumer_application[:key], @consumer_application[:secret], 
{
  :site               => 'http://api.sandbox-soundcloud.com', 
  :request_token_path => '/oauth/request_token',
  :access_token_path  => '/oauth/access_token',
  :authorize_path     => '/oauth/authorize'
}

# Obtain an oAuth request token
puts "Get request token"
request_token = @consumer.get_request_token