2012-02-03 8 views
29

Sto scrivendo un sito con un pulsante personalizzato tweet che utilizza la funzione www.twitter.com/share, tuttavia il problema che sto riscontrando è includere caratteri hash "#" all'interno del testo tweet.Come si comprendono gli hashtag all'interno del testo del link di condivisione di Twitter?

Ad esempio:

http://www.twitter.com/share?url=www.example.com&text=I+am+eating+#branstonpickel+right+now
Il testo Tweet esce come 'sto mangiando' e omette l'hash e tutto dopo.

Ho avuto una rapida occhiata sui forum di Twitter e ho appreso che il carattere "#" dell'hash non può essere parte dell'URL della condivisione.
Su https://dev.twitter.com/discussions/512#comment-877 si è detto che:

Gli hash sono caratteri speciali nell'URL (identificano frammenti di documento) in modo che, qualsiasi cosa e in seguito, non ottiene inviato al server.

e

è necessario UrlEncode esso, in modo da utilizzare% 23

Quando ho provato il secondo punto della mia link di prova:

www.twitter.com /share?url=www.example.com & text = I + am + eating +% 23branstonpickel + right + now
La cam di testo tweet e out come 'Sto mangiando% 23branstonpickel adesso' includendo letteralmente% 23 invece di convertirlo in un hash.

Ci scusiamo per la domanda scialba, ma qualcuno sa cosa si sta sbagliando?
Qualsiasi commento sarebbe molto apprezzato :)

risposta

64

Sembra che questa è la configurazione di base:

https://twitter.com/intent/tweet? 
url=<url to tweet> 
text=<text to tweet> 
hashtags=<comma separated list of hashtags, with no # on them> 

Questo sarebbe pre-costruito un tweet di: <text> <url> <hashtags>

L'esempio potrebbe essere: https://twitter.com/intent/tweet?url=http://www.example.com&text=I+am+eating+branston+pickel+right+now&hashtags=bransonpickel,pickles

C'era un bug con il parametro hashtag ... mostrava solo i primi hashtag n-1. Attualmente questo è risolto.

+3

Appare che il bug "n-1" è stato risolto ora – MJB

+0

Grazie per la risposta. È stato utile per me :) –

+0

Questo non funziona più. – RolandiXor

3

Posso sbagliarmi, ma penso che la hashtag deve essere passato come una variabile indipendente che apparirà alla fine del vostro cioè Tweet:

http://www.twitter.com/share?url=www.example.com&text=I+am+eating+branston+pickel+right+now&hashtag=bransonpickel

comporterà "Sto mangiando branston pickel in questo momento #branstonpickle"

In una nota a parte, penso che pickel dovrebbe essere sottaceto!

Acclamazioni

Toby

+0

Questo non funziona –

+1

Ha fatto 11 mesi fa! L'intento api è stato ulteriormente formalizzato per funzionare in questo modo: http://twitter.com/intent/tweet?text=I+am+eating+branston+pickel+right+now&url=www.example.com&hashtags=branstonpickel – idodev

+0

e branson dovrebbe essere Branston :) –

2

Se stai usando PHP, è possibile utilizzare il seguente:

<?php echo 'http://www.twitter.com/share?' . http_build_query(array(
    'url' => 'http://www.example.com', 
    'text' => 'I am eating #branstonpickel right now' 
)); ?> 

Questo farà tutte le codifiche URL per te, ed è facile da leggere.

Per ulteriori informazioni sul http_build_query, vedere il manuale di PHP: http://us2.php.net/http_build_query

1

uso encodeURIComponent per codificare l'URL

0

per l'URL con line jump, #, @ e unicode di speciale in esso, i seguenti lavori:

var lineJump = encodeURI(String.fromCharCode(10)), 
hash = "%23", arobase="%40", 
tweetText = 'https://twitter.com/intent/tweet?text=Le signe chinois '+hans+' '+item.pinyin+': '+item.definition.replace(";",",")+'.' 
    +lineJump+'Merci '+arobase+'Inalco_Officiel '+arobase+'CRIparis ❤️ ' 
    +lineJump+hash+'Chinois '+hash+'MOOC' 
    +lineJump+'https://hanzi.cri-paris.org/', 
tweetTxtUrlEncoded = tweetText+ "" +encodeURIComponent('#'+lesson+encodeURIComponent(hans)); 
Problemi correlati