<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:Courier New,courier,monaco,monospace,sans-serif;font-size:12pt"><div><br></div><div style="font-family: Courier New,courier,monaco,monospace,sans-serif; font-size: 12pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> J. Shirley <jshirley@gmail.com><br><b><span style="font-weight: bold;">To:</span></b> The elegant MVC web framework <catalyst@lists.scsys.co.uk><br><b><span style="font-weight: bold;">Sent:</span></b> Thu, October 15, 2009 9:44:13 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Catalyst] Facebook canvas application in Catalyst<br></font><br>
<div class="gmail_quote">On Thu, Oct 15, 2009 at 12:25 PM, Gunnar Strand <span dir="ltr"><<a rel="nofollow" ymailto="mailto:gunnarstrand@yahoo.com" target="_blank" href="mailto:gunnarstrand@yahoo.com">gunnarstrand@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I am trying to write a Facebook canvas application in Catalyst using the WWW::Facebook::API plugin and I am tearing my hair trying to get it to work.<br>
<br>
I have no problems with access to my canvas application from Facebook, but I am unable to use any of the $c->facebook interface methods to acquire user data, eg. friend list, event information etc.<br>
<br>
I would be very grateful if anyone could post an example of, for instance, getting the currently logged in user's friends, or event information or any information at all via the $c->facebook interface. All I get is error when using the methods in the interface and the problem is definitely on this side of the keyboard.<br>
<br>
KR,<br>
Gunnar<br>
</blockquote><div><br><br>Hi Gunnar,<br><br>I've been meaning to write a blog entry on this, since there are some points to be aware of. I've built my own model that creates a per-context instance and works quite well. It isn't on CPAN (yet) but I should probably release it.<br>
<br>I would advise against using the Plugin, as it's not modifying the application behavior or dispatching so having it as a plugin is a bad fit.<br><br><span>I posted my code in a gist: <a target="_blank" href="http://gist.github.com/211218">http://gist.github.com/211218</a> </span><br>
</div></div><br>Keep in mind that you can't do differentiation on request type like GET/POST through the canvas. Make sure that you have the application added to your profile (check the app added, there is a chain mid-point to do this in the gist).<br>
<br>Hope this helps,<br><br>-J<br><br>Hi J,<br><br>Thank you for the quick reply! I have looked through the code and I cannot understand what the problem is for me. I have tried making this as simple as possible to eliminate any potential errors and still don't get it to work. I removed the plugin and I now have this code in the top index, some shamelessly copied from your page :-):<br><br><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">sub index : Path : Args(0) {</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> my ( $self, $c ) = @_;</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> my $client = new
WWW::Facebook::API(</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> app_id => '174563349128',</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> api_key => 'ce82845d86baa6d633efa5f00d83575a',</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> desktop => 0,</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> secret => '<secret id>',</span><br style="font-family:
Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> );</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> my $params = $c->req->params;</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> my $fb_params = $client->canvas->get_fb_params( $c->req );</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> if (
$params->{'auth_token'} ) {</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> $client->auth->get_session( $params->{'auth_token'} );</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> }</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> if ( $fb_params->{session_key} ) {</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">
$client->session_key( $fb_params->{session_key} );</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> }</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> </span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> use Data::Dumper;</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> my $output = Dumper( $client->friends->get );</span><br style="font-family: Courier
New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> $c->response->body( '<pre>' </span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> . $output </span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> . '</pre>'</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> );</span><br style="font-family: Courier
New,courier,monaco,monospace,sans-serif;"><br>And the output is still:<br><br><pre>$VAR1 = {<br> 'error_msg' => 'Incorrect signature',<br> 'request_args' => [<br> {<br> 'value' => 'ce82845d86baa6d633efa5f00d83575a',<br> 'key' => 'api_key'<br> },<br> {<br> 'value' => 'JSON',<br> 'key' => 'format'<br> },<br> {<br> 'value' => 'facebook.friends.get',<br> 'key' => 'method'<br> },<br> {<br> 'value' => '2.0POf_Dzs6W1VEJY2ZW1J5A__.86400.1255726800-100000257794276',<br> 'key'
=> 'session_key'<br> },<br> {<br> 'value' => '1.0',<br> 'key' => 'v'<br> },<br> {<br> 'value' => 'f5558065b76063dd63a8777eb5da8d7a',<br> 'key' => 'sig'<br> }<br> ],<br> 'error_code' => 104<br> };</pre><br><br>I've rechecked the api_key and secret, and they are correct. I guess that that the source above really should product useful output?<br><br>KR,<br>Gunnar<br>
</div></div></div></body></html>