Assistente Onebox, rastreie essas visualizações de forma confiável!

O que faz

Transforma esse tipo de resultado:

(onde seu servidor falhou ao recuperar o código-fonte da página e, portanto, não pode extrair as tags necessárias para criar o onebox)

Nisso aqui!:

Ele simplesmente fornece um caminho alternativo para o onebox obter o código-fonte da página para buscar metadados quando o servidor de destino recusa sua conexão.

Ele não altera nada sobre como o onebox processa o código-fonte da página para encontrar os metadados e renderizar a caixa.

Ele foi criado para permitir que você insira os detalhes e credenciais de uma API de terceiros para recuperar a página em vez de fazer uma chamada HTTP normal diretamente para a página de destino.

Por que

Descobri que meus servidores estavam sendo impedidos de acessar vários sites comerciais, fazendo com que os oneboxes falhassem na renderização. Isso essencialmente ajuda a aproveitar a confiabilidade da API de terceiros, um pouco como um serviço de e-mail.

Por que é econômico

Você pode usar um VPS relativamente barato e ainda obter funcionalidade confiável de one-boxing, mesmo que seu IP ou user agent esteja de alguma forma “na lista negra”.

Você não precisa disso se

Você já consegue fazer onebox de todo o seu conteúdo de destino corretamente com a instalação padrão e todos os usuários estão satisfeitos.

Pré-requisitos

Você precisa de uma conta com uma API de terceiros adequada.

Configurações

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

O exemplo acima usa o embed.rocks, mas no futuro o suporte a outras APIs pode ser adicionado; no entanto, o embed.rocks oferece bom custo-benefício atualmente.

onebox assistant api base query:   ?url=

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

onebox assistant api page source field:   source

Você também precisará inserir sua chave de API fornecida pelo embed.rocks.

Veja o exemplo abaixo:

Essa configuração permite ignorar o prefetch (para verificar se a raspagem direta retorna um resultado) e usar a API desde o início.

image
padrão DESATIVADO

Recomendo definir isso como VERDADEIRO.

Isso é mais caro, é claro, mas frequentemente produz melhores resultados, pois há casos em que o prefetch é redirecionado para a página errada porque você não é confiável.

Informações de suporte

Lembre-se: se você já tentou fazer onebox de um link anteriormente, o núcleo do Discourse armazenará o resultado em cache.

Você pode adicionar uma string de consulta aleatória no final para contornar o cache: https://mylink.com/todaynews?random=random

Você também pode verificar se a API está respondendo, por exemplo:

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: %%%sua-chave-api%%%"

Você precisa codificar em URL o site que está chamando (o valor do parâmetro url) usando algum site como este (não garantimos a confiabilidade!).

Limitações conhecidas

  • Foi testado apenas com um provedor no momento e não foi testado em outros. Esse provedor é https://embed.rocks (com quem não tenho afiliação). Estou disposto a considerar o suporte a mais serviços se o trabalho for patrocinado.

  • A modificação (monkey patching) é feita no nível do método. Isso substitui mais código do que o necessário, o que aumenta o risco de o plugin quebrar após uma atualização do núcleo. No entanto, não acho que haja uma maneira de minimizar isso ainda mais?

Como instalar plugins

Veja o guia aqui: Install plugins on a self-hosted site

Este repositório é: https://github.com/merefield/discourse-onebox-assistant

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

Todos os feedbacks são bem-vindos. Por favor, dê uma :star: no GitHub se achar útil.

41 curtidas

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 curtidas

Wow…

Ok, that worked…

Thanks man :bowing_man:

4 curtidas

With the plugin installed? @Richie

1 curtida

@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 curtidas

with the plugin installed?

1 curtida

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 curtidas

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 curtidas

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

2 curtidas

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 curtida

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 curtidas

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 curtida

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 curtidas

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 curtida

I’ve added plaintext to the OP for you.

3 curtidas

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 curtida

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 curtida

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 curtida

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 curtidas