مساعد Onebox، استرجع تلك المعاينات بشكل موثوق!

ما الذي يفعله

يحوّل نتائج من هذا النوع:

(حيث فشل خادمك في جلب مصدر الصفحة، وبالتالي لا يمكنه استخراج الوسوم المطلوبة لبناء الـ onebox)

إلى هذا!

يوفر ببساطة مسارًا بديلًا للـ onebox للحصول على مصدر الصفحة الذي يبحث فيه عن البيانات الوصفية عندما يرفض الخادم المستهدف اتصالك.

لا يغير شيئًا في كيفية معالجة الـ onebox لمصدر الصفحة بعد ذلك للعثور على البيانات الوصفية وعرض الصندوق.

يهدف إلى تمكينك من إدخال تفاصيل ومفاتيح واجهة برمجة تطبيقات (API) تابعة لجهة خارجية لجلب الصفحة بدلاً من إجراء استدعاء HTTP عادي مباشرةً إلى الصفحة المستهدفة.

لماذا

وجدت أن خوادمى مُنعت من الوصول إلى عدد من المواقع التجارية، مما أدى إلى فشل عرض الـ oneboxes. يساعد هذا الحل فعليًا في الاستفادة من موثوقية واجهة برمجة التطبيقات التابعة لجهة خارجية، تشبه إلى حد ما خدمة البريد.

لماذا يعتبر فعالًا من حيث التكلفة

يمكنك استخدام خادم افتراضي خاص (VPS) رخيص نسبيًا، مع الحصول على وظيفة موثوقة لعرض الـ oneboxes، حتى لو كان عنوان IP الخاص بك أو وكيل المستخدم (User Agent) مدرجًا في القائمة السوداء بطريقة ما.

لن تحتاج إليه إذا

كنت تعرض محتوى جميع أهدافك بنجاح باستخدام التثبيت الافتراضي (Vanilla install) وكان جميع المستخدمين راضين.

المتطلبات المسبقة

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

الإعدادات

onebox assistant api base address:  https://api.embed.rocks/api/

المثال أعلاه يستخدم embed.rocks، ولكن في المستقبل قد يتم دعم واجهات برمجة تطبيقات أخرى، ومع ذلك، فإن embed.rocks تقدم قيمة جيدة حاليًا.

onebox assistant api base query:   ?url=

onebox assistant api options:   &skip=article,description,oembed,imextra&include=source

onebox assistant api page source field:   source

ستحتاج أيضًا إلى إدخال مفتاح واجهة برمجة التطبيقات (API Key) الذي قدمته لك embed.rocks.

انظر المثال أدناه:

يسمح لك هذا الإعداد بتجاهل الاسترجاع المسبق (للتحقق مما إذا كان الزحف المباشر يعيد نتيجة) واستخدام واجهة برمجة التطبيقات من البداية.

image
الإعداد الافتراضي: OFF

أوصي بتعيين هذا الإعداد على TRUE.

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

معلومات الدعم

تذكر، إذا كنت قد حاولت سابقًا إنشاء صندوق onebox لروابط، فإن نواة Discourse ستخزن النتيجة مؤقتًا.

يمكنك إضافة سلسلة استعلام عشوائية في النهاية للتغلب على التخزين المؤقت: https://mylink.com/todaynews?random=random

يمكنك أيضًا التحقق من استجابة واجهة برمجة التطبيقات (API) باستخدام أمر مثل:

curl -X GET "https://api.embed.rocks/api/?url=https%3A%2F%2Fnews.bbc.co.uk%0A&skip=article,description,oembed,imextra&include=source" -H "x-api-key: %%%your-api-key%%%"

يجب عليك ترميز الموقع الذي تتصل به (قيمة معلمة url) باستخدام موقع مثل هذا مثل هذا (لا نضمنه!).

قيود معروفة

  • تم اختباره حاليًا مع مزود واحد فقط ولم يتم اختباره مع الآخرين. هذا المزود هو https://embed.rocks (وليس لدي أي ارتباط به). أنا مستعد للنظر في دعم المزيد من الخدمات إذا تم تمويل العمل.

  • يتم عمل التصحيح (Monkey patching) على مستوى الطريقة (method level). هذا يتجاوز المزيد من الكود مما هو ضروري، مما يؤدي إلى زيادة خطر تعطل الإضافة بعد تحديث النواة. ومع ذلك، لا أعتقد أن هناك طريقة لتقليل هذا أكثر؟

كيفية تثبيت الإضافات

راجع الدليل هنا: Install plugins on a self-hosted site

هذا المستودع هو: https://github.com/merefield/discourse-onebox-assistant

كل التعليقات موضع ترحيب. يرجى :star: الإضافة على GitHub إذا وجدت أنها مفيدة.

41 إعجابًا

Sorry I haven’t had a chance to rebuild our site with this addon enabled, I’ll do so tonight.

@WaitroseCarpark I didn’t fill out anything like that, steps I followed are:

Step 1:

Step 2:

Step 3:

Step 4:
do the robot check

Step 5:
add oEmbed api


sign your life away
image
green tick for oEmbed
image

Step 6:
get creds from Settings > Basic

Step 7:
get an app token

with the creds from above, run

curl -X GET "https://graph.facebook.com/oauth/access_token?client_id={your-app-id}&client_secret={your-app-secret}&grant_type=client_credentials"

which returns

{"access_token":"378384926723309|xxxxxx","token_type":"bearer"}

test your auth token

curl -X GET \ "https://graph.facebook.com/v9.0/instagram_oembed?url=https://www.instagram.com/p/fA9uwTtkSN/&access_token=xxxx..."

which returns

{"version":"1.0","author_name":"diegoquinteiro","provider_name":"Instagram","provider_url":"https:\/\/www.instagram.com\/","type":"rich","width":658,"html":"\u003Cblockquote class=\"instagram-media\" data-instgrm-captioned data-instgrm-permalink=\"https:\/\/www.instagram.com\/p\/fA9uwTtkSN\/?utm_source=ig_embed&utm_campaign=loading\" ....

Add to discourse and you’re done!

6 إعجابات

Wow…

Ok, that worked…

Thanks man :bowing_man:

4 إعجابات

With the plugin installed? @Richie

إعجاب واحد (1)

@znedw Thank you so much for taking the time to explain step by step (with pictures! :heart_eyes:) how to do this! Works a charm as far as I can see!

3 إعجابات

with the plugin installed?

إعجاب واحد (1)

I only actually noticed you’ve made this plugin just now…I was not using it, sorry for hijacking your thread.

BUT, I will try it out later today if I can find some spare time…

إعجابَين (2)

I spent half an hour or so this evening trying all manner of possible permutations, Robert @merefield

Following the steps provided by @znedw (thanks again my man!) it would appear that this method works both with the Onebox Assistant enabled, and with it disabled too (via admin panel, plugins, checkbox).

I’ve not tried rebuilding my Discourse with the plugin completely removed.

Perhaps worth a note, I do not have the option enabled for “Always use the proxy crawl regardless of direct response”.

Off topic, it would appear amazon.co.uk are blocking all manner of requests again, both directly (plugin disabled) and also via embed.rocks “try it” page, which also times out :roll_eyes:

3 إعجابات

Thanks. Yes I expected it to work at least without the “always use the proxy”

إعجابَين (2)

On the subject of Amazon I always use their affiliate links anyway, manually, which are not blocked.

Oneboxing breaches their T&Cs if you are an affiliate.

Highly recommend you consider the affiliate membership. It doesn’t net a fortune but may pay for the server and mail fees.

إعجاب واحد (1)

Is it possible to use this plugin only for YouTube links? Can’t understand what settings should I use for this.
And also where can I find more info about possible settings?
Thank you!

No. You’d have to fork and develop the code further.

Just copy those in the OP exactly. You will have your own key.

إعجابَين (2)

How can I check if the plugin working and the queries are going through https://embed.rocks?
I activated it, but the error hasn’t gone.

I test with these videos:

https://www.youtube.com/watch?v=_2wfBNUnOVY
https://www.youtube.com/watch?v=qLNhVC296YI
إعجاب واحد (1)

The dashboard on embed.rocks should start reflecting your calls (a local counter is a nice-to-have but have not yet implemented one)

Both of those links work for me via the plugin.

If it’s not working, try checking this option:

image

إعجابَين (2)

Are all settings you have equal to those in the picture you gave? Maybe I have a mistake when typing them. Any option to copy them?

إعجاب واحد (1)

I’ve added plaintext to the OP for you.

3 إعجابات

Thank you. I checked and everything was correct. I can’t see any call on the Dashboard page in the Usage section. Does it mean smth is wrong? Should the number of calls always be visible?

إعجاب واحد (1)

You’d need to ask embed.rocks that question. At some point I may add additional logging to the plugin which might help. You might be able to set your site to log level ‘info’ to get more information however, as there are existing calls to Rails.logger.info

إعجاب واحد (1)

Yeah, that would be great. Because now I activated the plugin and configured the settings, but youtube is not working and there is no activity on the Dashboard. I sent an email to the embed.rocks support.

إعجاب واحد (1)

Will this plugin work correctly if I store files at Amazon S3?
I still struggle with it and can’t make it working. Videos are not uploaded - only links. And there is no information on the Usage Panel of the Embed.rocks

I have a testing server. Files are stored locally on it. But the plugin also doesn’t work and there is no activity on the Usage dashboard. But videos are saved on the site.

So I can’t understand how and what to check to solve the problem.

Please, help with your ideas.

إعجابَين (2)