Assistenza Onebox, esegui la scansione di quelle anteprime in modo affidabile!

Cosa fa

Trasforma questo tipo di risultato:

(dove il tuo server non è riuscito a recuperare il codice sorgente della pagina e quindi non può estrarre i tag necessari per costruire la onebox)

In questo!:

Fornisce semplicemente un percorso alternativo per permettere alla onebox di ottenere il codice sorgente della pagina necessario per cercare i metadati quando il server di destinazione rifiuta la tua connessione.

Non cambia nulla nel modo in cui la onebox elabora successivamente il codice sorgente della pagina per trovare i metadati e rendere la box.

È pensato per permetterti di inserire i dettagli e le credenziali di un’API di terze parti per recuperare la pagina invece di effettuare una normale chiamata HTTP direttamente alla pagina di destinazione.

Perché

Ho notato che i miei server venivano bloccati dall’accesso a diversi siti commerciali, causando il fallimento del rendering delle onebox. In sostanza, aiuta a sfruttare l’affidabilità di un’API di terze parti, un po’ come un servizio di posta.

Perché è conveniente

Puoi utilizzare un VPS relativamente economico ma ottenere comunque una funzionalità di one-boxing affidabile, anche se il tuo IP o user agent sono in qualche modo “in blacklist”.

Non ti serve se

Stai già ottenendo correttamente le onebox per tutto il tuo contenuto target con l’installazione standard e tutti gli utenti sono soddisfatti.

Prerequisiti

Hai bisogno di un account con un’API di terze parti adatta.

Impostazioni

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

L’esempio sopra utilizza embed.rocks, ma in futuro potrebbe essere aggiunto il supporto per altre API; tuttavia, al momento embed.rocks offre un buon rapporto qualità-prezzo.

onebox assistant api base query:   ?url=

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

onebox assistant api page source field:   source

Dovrai anche inserire la tua chiave API fornita da embed.rocks.

Vedi l’esempio sottostante:

Questa impostazione ti permette di ignorare il prefetch (per verificare se il crawl diretto restituisce un risultato) e utilizzare l’API fin dall’inizio.

image
di default OFF

Consiglio di impostare questa opzione su TRUE.

È ovviamente più costoso, ma spesso produce risultati migliori, poiché ci sono casi in cui il prefetch viene reindirizzato alla pagina sbagliata perché non sei considerato attendibile.

Informazioni sul supporto

Ricorda che se hai già tentato di creare una onebox per un link, il core di Discourse memorizzerà il risultato nella cache.

Puoi aggiungere una stringa di query casuale alla fine per superare la cache: https://mylink.com/todaynews?random=random

Puoi anche verificare che l’API stia rispondendo, ad esempio con:

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%%%"

Devi codificare in URL il sito che stai chiamando (il valore del parametro url) utilizzando un sito come questo (non garantito!).

Limitazioni note

  • È stato testato finora solo con un provider e non su altri. Tale provider è https://embed.rocks (con il quale non ho alcuna affiliazione). Sono disponibile a valutare il supporto per altri servizi se il lavoro viene sponsorizzato.

  • La modifica (monkey patching) viene eseguita a livello di metodo. Questo sovrascrive più codice del necessario, aumentando il rischio che il plugin si rompa dopo un aggiornamento del core. Tuttavia, non penso esista un modo per minimizzare ulteriormente questo aspetto?

Come installare i plugin

Vedi la guida qui: Install plugins on a self-hosted site

Questo repository è: https://github.com/merefield/discourse-onebox-assistant

https://github.com/merefield/discourse-onebox-assistant

Tutti i feedback sono benvenuti. Per favore :star: il progetto su GitHub se lo trovi utile.

41 Mi Piace

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 Mi Piace

Wow…

Ok, that worked…

Thanks man :bowing_man:

4 Mi Piace

With the plugin installed? @Richie

1 Mi Piace

@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 Mi Piace

with the plugin installed?

1 Mi Piace

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 Mi Piace

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 Mi Piace

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

2 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

I’ve added plaintext to the OP for you.

3 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace