erik_chan
(Erik Chan)
2015 年 10 月 28 日午後 10:30
1
I am receiving the following error:
DiscourseApi::UnauthenticatedError:
{"errors"=>["You are not permitted to view the requested resource."], "error_type"=>"invalid_access"}
when I make the ruby API call ‘category_latest_topics’
response = client.category_latest_topics("<some_category>")
This is due to the category permissions (the category is not public). I tried to authenticate by using
client.api_username = "system"
and making sure “system” is a member of the group that has permissions to the category but still no luck! Any suggestions or workarounds?
「いいね!」 2
erik_chan
(Erik Chan)
2015 年 10 月 30 日午前 3:12
2
No response so far. Am I posting this in the right forum?
Try using a different user, other than System. Issue an API key for a different user. You will need to experiment.
erik_chan
(Erik Chan)
2015 年 10 月 30 日午前 4:18
4
No luck. Tried issuing API key for different users who have permission to the category but still no access.
erik_chan
(Erik Chan)
2015 年 11 月 1 日午後 8:15
5
Would be awesome if anyone else has suggestions for this?
How can I access a private category via the API. This should not be an issue for users/system with admin rights to the forum.
chenny408
(Chenny408)
2015 年 11 月 4 日午前 2:58
6
I’m having the same issue, can someone take a look into this?
「いいね!」 1
purldator
(mountain)
2015 年 11 月 5 日午前 5:27
7
Have you attempted to generate a key from your account? You are the admin who created the forum, yes? You say “users/system” so I am wondering if you tried your own account.
erik_chan
(Erik Chan)
2015 年 11 月 5 日午前 5:41
8
Yes i am the admin of my forum.
I have tried both my username and system with no luck. I can’t call client.category_latest_topics(<category_name>) even though the user has permissions to the category
purldator
(mountain)
2015 年 11 月 5 日午前 5:53
9
I feel some other variable exists and is causing this error; one that cannot be seen due to the limited info provided.
Be sure to check these topics in regards to setting up and using the Discourse API, if you have not yet done so.
So you want to use Discourse API ? Great! Let’s get started.
Set up Discourse development environment
Set up Discourse development environment using our Windows , OS X or Ubuntu guide.
Clone Discourse API Gem
Now that you have set up Discourse development environment, you should already have Git and Ruby installed on your system. You can install Discourse API gem by running following command from console:
git clone https://github.com/discourse/discourse_api.git ~/discourse_api
Install depend…
Discourse API
Please view the Discourse API Documentation site for detailed info:
https://docs.discourse.org
Deprecation Warning!
On April 6th, 2020 we dropped support for all non-HTTP header based authentication (excluding some rss, mail-receiver, and ics routes). This means that API requests that have an api_key and api_username in the query params or in the HTTP body of the request will soon stop working. Please see the example cURL request below for how to update your API requ…
Discourse is backed by a complete JSON api. Anything you can do on the site you can also do using the JSON api.
Many of the endpoints are properly documented in the discourse_api gem, however some endpoints lack documentation.
To determine how to do something with the JSON API here are some steps you can follow.
Example: recategorize a topic.
Go to a topic and start editing a category:
[image]
Open Chrome dev tools, switch to the Network tab, select XHR filter:
[image]
Perform the op…
erik_chan
(Erik Chan)
2015 年 11 月 5 日午前 6:15
10
Appreciate your help. If you read my original post i am using the ruby api. I have also looked through the documentation before posting this topic.
If you could show me what variable i am missing or where to exactly to find out more i would appreciate it.
「いいね!」 1
j127
2020 年 6 月 19 日午後 8:28
13
現在、同じ問題に直面している方はいますか?API を使おうとして 2 日間試していますが、毎回同様のエラーが発生します。手順を見落としているのか、それとも何かが変更されたのか分かりません。
system ユーザー用に新しい API キーを作成しました。また、すべてのユーザー用に API キーを作成し、その後で管理者アカウントを使用することも試みました。
discourse_api Ruby gem を使用した場合:
DiscourseApi::UnauthenticatedError ({"errors"=>["You are not permitted to view the requested resource. The API username or key is invalid."], "error_type"=>"invalid_access"})
別の投稿から以下のコードも試しました:
require 'net/http'
require 'uri'
INSTANCE_URL = 'https://forum.example.com/admin/users/list/all.json?email=user@example.com'
API_USERNAME = 'system'
API_KEY = 'a_new_api_key_here'
def send_request
url = URI.parse(INSTANCE_URL)
request = Net::HTTP::Get.new(url.path)
request.set_form_data({'api_username' => API_USERNAME, 'api_key' => API_KEY})
http = Net::HTTP.new(url.host, url.port)
response = http.request(request)
if response.code == '200'
puts "Success!"
else
puts "Error"
puts response.code
end
end
send_request # 400
また、api_username と api_key をフォームデータに含めて生リクエストを送信する方法も試しましたが、404 エラーが発生しました。
メールアドレスのリストを読み込み、ユーザー名を取得し、その後でそのユーザーをすべての Discourse メール購読から解除するスクリプトを作成しようとしています。
simon
2020 年 6 月 19 日午後 10:45
14
生の Ruby コードで発生しているエラーについてですが、問題は Api-Key と Api-Username をリクエストヘッダーに設定する必要がある点です。また、API フィールド名はアンダースコア(_)ではなくハイフン(-)を使用する必要があります。詳細については、https://docs.discourse.org/ の上部にある「Authentication」セクションを参照して、リクエストの認証方法を確認してください。
Discourse API gem を使用して呼び出しを行った際にエラーが発生する原因については、現時点では特定できていません。最も考えられる原因は、正しい API 認証情報を使用していないことです。ユーザーレベルが「All Users」に設定された API キーを使用しているか確認してください。
それでも問題が解決しない場合は、実行しようとしているリクエストをここに投稿してください。確認いたします。
「いいね!」 5
j127
2020 年 6 月 19 日午後 11:18
15
ありがとうございます、動作しました。最初の数件の投稿こちら を参考にしていたのですが、更新が必要かもしれません:
「いいね!」 2
simon
2020 年 6 月 19 日午後 11:55
16
ご指摘ありがとうございます。OP を更新し、トピックから最も古い投稿を削除しました。
「いいね!」 3