احصل على عنوان البريد الإلكتروني لمستخدم عبر واجهة برمجة التطبيقات

هل توجد طريقة للحصول على عنوان البريد الإلكتروني الحالي للمستخدم عبر واجهة برمجة التطبيقات (API)؟

حالة الاستخدام لدينا كالتالي:

نسمح للمستخدمين بإدارة معلوماتهم في Discourse عبر موقعنا الإلكتروني. بشكل عام، يُستخدم Discourse فقط كقائمة بريدية، ولا يزور معظم المستخدمين موقع Discourse الفعلي أبدًا. أريد أن أتمكن من عرض عنوان البريد الإلكتروني الحالي الذي يستخدمه Discourse للمستخدم، حتى يتمكن من معرفة ما إذا كان يحتاج إلى تغيير.

أستطيع القيام بذلك مع جميع الحقول الأخرى باستثناء البريد الإلكتروني.

كان هناك نقطة نهاية (endpoint) في واجهة برمجة التطبيقات تُسمى users/{username}/emails، لكنها لا تبدو متاحة بعد الآن.

Hi,

GET /users/:username.json

will display the email in two cases:

  • the user id of the API KEY holder is the same than the user id related to the requested username
  • the API KEY holder is staff and the requested user is staged

Read more about this in code:

AFAIK this codepath has not changed recently.

3 إعجابات

Yeah, but that doesn’t help me. All of the users are already active and the user API key is not going to match.

This request does work for me:

curl "http://example.com/users/joffreyjaffeux/emails.json" \
     -H 'Api-Username: joffreyjaffeux' \
     -H 'Api-Key: xxx' \
     -H 'Content-Type: application/json; charset=utf-8' \
3 إعجابات

But, does it work if the URL is http://example.com/users/paulapostolos/emails.json ?

Yes it should work for yourself and other users as long as this is true:

  def can_check_emails?(user)
    is_admin? || (is_staff? && SiteSetting.moderators_view_emails)
  end

Note that doing so will trigger a staff action log.

4 إعجابات

That worked…I had some old code that used to work (version 1.4 ish) that had the request as a PUT and without the .json at the end. I modified it to a GET and changed the URL and now it works.

Thanks for the help!

3 إعجابات