erik_chan
(Erik Chan)
28 أكتوبر 2015، 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?
erik_chan
(Erik Chan)
30 أكتوبر 2015، 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)
30 أكتوبر 2015، 4:18ص
4
No luck. Tried issuing API key for different users who have permission to the category but still no access.
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.
I’m having the same issue, can someone take a look into this?
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.
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
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)
5 نوفمبر 2015، 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.
j127
19 يونيو 2020، 8:28م
13
هل يعاني أي شخص آخر من هذه المشكلة في الوقت الحالي؟ لقد حاولت لمدة يومين استخدام واجهة برمجة التطبيقات (API)، لكنني أحصل على أخطاء مماثلة في كل مرة. لست متأكدًا مما إذا كنت أفتقد خطوة ما أو إذا كان هناك تغيير ما.
لقد أنشأت مفتاح واجهة برمجة تطبيقات (API) جديدًا لمستخدم system. كما جربت إنشاء مفتاح واجهة برمجة تطبيقات (API) لجميع المستخدمين ثم استخدام حساب المسؤول الخاص بي.
باستخدام مكتبة discourse_api بلغة Ruby:
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) عن طريق وضع api_username و api_key في بيانات النموذج مع طلب خام، لكنني حصلت على خطأ 404.
أحاول كتابة نص برمجي يقرأ قائمة عناوين البريد الإلكتروني، ويحصل على أسماء المستخدمين، ثم يلغي اشتراكهم من جميع رسائل Discourse البريدية.
simon
19 يونيو 2020، 10:45م
14
بالنسبة للخطأ الذي تواجهه مع كود Ruby الخام، فإن المشكلة تكمن في أن Api-Key و Api-Username يجب تعيينهما في رؤوس الطلب (request headers). كما يجب أن تستخدم أسماء الحقول في الـ API شرطات (-) بدلاً من الشرطات السفلية (_). راجع قسم المصادقة في أعلى https://docs.discourse.org/ للحصول على تفاصيل حول كيفية مصادقة الطلب.
لست متأكدًا مما قد يسبب الخطأ عند إجراء المكالمة باستخدام مكتبة Discourse API. السبب الأكثر احتمالًا للمشكلة هو أنك لا تستخدم بيانات اعتماد API صحيحة. تأكد من استخدام مفتاح API تكون فيه مستوى المستخدم مضبوطًا على “جميع المستخدمين”:
إذا لم يحل ذلك المشكلة بالنسبة لك، فقم بنشر الطلب الذي تحاول إجراؤه هنا وسألقِ نظرة عليه.
j127
19 يونيو 2020، 11:18م
15
شكرًا لك، هذا يعمل. كنت أتبع أول بضع منشورات هنا ، وقد يحتاج هذا إلى تحديث:
simon
19 يونيو 2020، 11:55م
16
شكرًا لك على الإشارة إلى ذلك. لقد قمت بتحديث المنشور الأصلي وحذفت أقدم المنشورات من الموضوع.