inherit
*this CT deserves an achievement*
136400
0
Jun 25, 2021 18:23:00 GMT -8
Trill
hola
6,232
January 2009
ghbraingle
|
Post by Trill on Jul 6, 2011 16:55:47 GMT -8
I'm working on a "News" area of my forum, and I'd like the comments to be via the Facebook API rather than replies to each thread. Facebook Comment Parameters: developers.facebook.com/docs/reference/fbml/comments/ (note the xid at the top of the parameter list) Basic version of the comments API: developers.facebook.com/docs/reference/plugins/comments/Assuming I understood what the "xid" parameter does, the best way to have a different set of comments of each news article/thread is to use the thread ID for the xid. Thus, I made the following edit to the code: <script> var newsid=document.location.href.split("thread=")[1]; </script>
<div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<script> document.write('<fb:comments href="http://godricshollow.info" num_posts="6" width="450" xid="'+newsid+'"></fb:comments>'); </script> However, this is still showing the same comments on all pages. I figure I must be doing something wrong, as this should be showing a different set of comments depending on which thread I'm in (if I'm using the xid parameter properly). *shrugs* Thanks in advance for any help.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jul 6, 2011 17:34:54 GMT -8
*** Not familiar with FBAPI ***
However, I'm not seeing an url to the forum where it's been implemented and off the bat I see a problem withvar newsid=document.location.href.split("thread=")[1];
if url is for example http://support.proboards.com/index.cgi?action=display&board=coderequests&thread=394614&page=1#4528111
the red would be your final newsid, I assume you only wanted 394614. So unless you have additional coding that limits the activation of that code somehow (which a forum url would reveal) then you'd probably want to use var newsid=document.location.href.match(/thread=(\d+)/)[1]; Assuming the API defaults to a standard comment stream if the xid is invalid then that would explain why it always shows same comments
|
|
inherit
*this CT deserves an achievement*
136400
0
Jun 25, 2021 18:23:00 GMT -8
Trill
hola
6,232
January 2009
ghbraingle
|
Post by Trill on Jul 6, 2011 17:51:17 GMT -8
Sorry Eton, here's where the code is implemented: godricshollow.info/index.cgi?board=dailyprophet&action=display&thread=1239Later I plan on adding a location check to make sure the viewer is in a thread (/action=display/) of that board. I figured while diagnosing the problem, the less code interfering, the better. You can see that viewing the boardindex of that board also shows the same comments that are in the thread. I've added in the variable correction, but there doesn't seem to be any difference in the comments displayed.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jul 6, 2011 19:35:12 GMT -8
Sorry for the delay but I had to take a glance at the API docs first, this is what I came up with
<div id="fb-root"></div>
<script> if(/&thread=(\d+)/.test(document.location.href)){ var getP = location.href.split('?')[1].split('#')[0].replace(/&?(\w+)=(\w+)/g,function(m,p){if(!/(board|thread)/.test(m))return ""; else return m;}) document.write('<scr'+'ipt src="http://connect.facebook.net/en_US/all.js#xfbml=1"></scr'+'ipt>') document.write('<fb:comments href="http://'+location.hostname+'/?'+getP+'" num_posts="6" width="450" xid="'+getP+'"></fb:comments>'); } </script>
Placed it on a test forum and it loaded separate comments for each individual thread
If you also want it showing on preview pages then you'll need to get the board and thread info from the form itself and manually reconstruct the GET parameters.
|
|
inherit
*this CT deserves an achievement*
136400
0
Jun 25, 2021 18:23:00 GMT -8
Trill
hola
6,232
January 2009
ghbraingle
|
Post by Trill on Jul 6, 2011 19:56:05 GMT -8
Perfect! Thank you very much. It works perfectly now. I notice you corrected the comments href parameter so facebook feeds link to the exact page now, which is even better.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jul 6, 2011 22:12:36 GMT -8
Cool... Actually to support custom domains it might be better to construct href using pb_forum rather than location.hostname so there would be no difference between viewing a thread with standard url or custom url.
|
|
inherit
*this CT deserves an achievement*
136400
0
Jun 25, 2021 18:23:00 GMT -8
Trill
hola
6,232
January 2009
ghbraingle
|
Post by Trill on Jul 7, 2011 10:25:53 GMT -8
No worries. I'd prefer the Facebook updates linking to the custom url rather than the pb url. I'll be adding an alert to members using the pb url that they should switch to using the custom domain anyway. Thanks again!
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jul 7, 2011 15:49:17 GMT -8
In that case you might want to try changing
<fb:comments href="http://'+location.hostname+'/?'+getP+ ...
to
<fb:comments href="http://godricshollow.info/?'+getP+
As you see, the href is the primary factor used to determine which comments to show, the XID is more of a preventive measure since without it the API creates one from the GET parameters in the url meaning you could get a "box swap" if viewing "&page=2" as opposed to viewing "&page=1". Someone using the standard url won't see comments made from the custom url and vice versa. By hard coding it like that, comments made from standard url (despite your warning alerts, comments WILL BE MADE) would be visible from the custom url and vice versa. A single, unified identifier for the thread should mean a single comment box regardless of which url is used.
|
|
inherit
*this CT deserves an achievement*
136400
0
Jun 25, 2021 18:23:00 GMT -8
Trill
hola
6,232
January 2009
ghbraingle
|
Post by Trill on Jul 7, 2011 19:35:28 GMT -8
You're right, that's very true. I just noticed, it seems that the API is recognizing different URLs depending on the order of items in the PB URL. I'm getting different comments from the same thread: http://godricshollow.info/index.cgi?action=display&board=dailyprophet&thread=1239 http://godricshollow.info/index.cgi?board=dailyprophet&action=display&thread=1239
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jul 8, 2011 16:10:00 GMT -8
You're right, that's very true. I just noticed, it seems that the API is recognizing different URLs depending on the order of items in the PB URL. I'm getting different comments from the same thread: http ://godricshollow .info/index.cgi?action=display&board=dailyprophet&thread=1239 http ://godricshollow .info/index.cgi?board=dailyprophet&action=display&thread=1239 The code I posted made no attempt to put the GET parameters in any particular order which is why you're getting that result. I made a few changes mainly to maintain a specific order for the XID (board first then thread) and also support custom domains. Give this one a shot (haven't tested since I have no custom domain to test on) <script type="text/javascript"> <!-- (function(customDomain){ if(/&thread=(\d+)/.test(document.location.href)){ var getP = ['',''], loc = customDomain||location.hostname; location.href.split('?')[1].split('#')[0].replace(/&?(\w+)=(\w+)/g,function(m,p1,p2){ i={board:0,thread:1}; if(p1 in i)getP[i[p1]]= p1 + '=' + p2; return m; }); getP = getP.join('&') document.write('<scr'+'ipt src="http://connect.facebook.net/en_US/all.js#xfbml=1"></scr'+'ipt>') document.write('<fb:comments href="http://' + loc + '/?' + getP + '" num_posts="6" width="450" xid="'+getP+'"></fb:comments>'); } })("godricshollow.info") // --> </script>If custom domain is omitted then it will use the domain from the url.
|
|
inherit
*this CT deserves an achievement*
136400
0
Jun 25, 2021 18:23:00 GMT -8
Trill
hola
6,232
January 2009
ghbraingle
|
Post by Trill on Jul 8, 2011 16:26:11 GMT -8
That seems to work perfectly, irrespective or URL order or domain. Thank you!
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jul 8, 2011 16:30:08 GMT -8
Just so you know, I'll be stealing this to replace the problematic Gigya commenting system, so thank you...
|
|
inherit
*this CT deserves an achievement*
136400
0
Jun 25, 2021 18:23:00 GMT -8
Trill
hola
6,232
January 2009
ghbraingle
|
Post by Trill on Jul 8, 2011 16:34:29 GMT -8
Not a problem. I saw Wormo's thread in Support about the API key, then found the Profile Comments code at wormocodes: very cool.
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jul 8, 2011 19:33:18 GMT -8
Ricky's reply made me sad.
|
|
Former Member
inherit
guest@proboards.com
198088
0
Nov 23, 2024 1:08:06 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Aug 11, 2013 21:53:22 GMT -8
hi RedBassett! FB comments don't work on ProBoards?
|
|