ElWardi/sfMelodyDemo — Issue #1: Access token failed issue
Author: battika
Created: 2011-11-29 21:52:51+00:00
State: open

Hello ElWardi,

Thanks for putting sfMelodyDemo example symfony project together. I'm wondering if you could give me some sort of direction as I cannot get the demo work.

Downloaded the code and followed your instructions to set it up. I'm using WAMP on Windows 7 and created a virtual host of **sfmelodydemo.dev** to match your setup and changed my Windows hosts file **sfmelodydemo.dev** pointing to **127.0.0.1**. Created a developer app on Facebook, set the Site URL field to sfmelodydemo.dev and finally ran `symfony doctrine:build --all --and-load` command to create the database backend. I think it should be all set.

When I open **http://sfmelodydemo.dev/frontend_dev.php** in my web browser it gives me two options to log on with, Facebook and Twitter. I choose Facebook which will redirect to my Facebook app page where I successfully log on with my Facebook account. When I get redirected to **sfmelodydemo.dev/frontend_dev.php** it throws an **internal server error 500 message, Doctrine_Table_Exception**, saying that `You must specify the value to findOneBy`. It occurs as inside the `executeFacebookSignup` action where we attempt to find out whether the email address is already present:
```
$dbUser = UserTable::getInstance()->findOneByEmailAddress($this->user->getEmailAddress());
```
Since **user->getEmailAddress()** returns **null**, findOneByEmailAddress function will fail.

The reason why it fails is we are unable to get a valid access token from Facebook. Here are some excerpts from the log file...

Initial authorize request seems fine. URL looks Okay.
```
Nov 29 21:06:25 symfony [info] {sfMelodyActions} Call "sfMelodyActions->executeFacebookConnect()"
Nov 29 21:06:25 symfony [info] {OAuth} "facebook" call url "https://graph.facebook.com/oauth/authorize" with params "array (
'scope' => 'email,user_birthday',
'client_id' => '280217605XXXXXX',
'redirect_uri' => 'http://sfmelodydemo.dev/frontend_dev.php/access/facebook',
)"
Nov 29 21:06:25 symfony [info] {sfFrontWebController} Redirect to "https://graph.facebook.com/oauth/authorize?scope=email%2Cuser_birthday&client_id=280217605XXXXXX&redirect_uri=http%3A%2F%2Fsfmelodydemo.dev%2Ffrontend_dev.php%2Faccess%2Ffacebook"
Nov 29 21:06:25 symfony [info] {sfWebResponse} Send status "HTTP/1.1 302 Found"
Nov 29 21:06:25 symfony [info] {sfWebResponse} Send header "Location: https://graph.facebook.com/oauth/authorize?scope=email%2Cuser_birthday&client_id=280217605XXXXXX&redirect_uri=http%3A%2F%2Fsfmelodydemo.dev%2Ffrontend_dev.php%2Faccess%2Ffacebook"
```

Then I get this issue of access token failed and a zero-sized array is returned:

```
Nov 29 21:06:27 symfony [info] {sfMelodyActions} Call "sfMelodyActions->executeAccess()"
Nov 29 21:06:27 symfony [info] {OAuth} call https://graph.facebook.com/oauth/access_token?client_id=280217605XXXXXX&client_secret=4ba259f0f6acfb44dfbe55XXXXXXXXXX&redirect_uri=http%3A%2F%2Fsfmelodydemo.dev%2Ffrontend_dev.php%2Faccess%2Ffacebook&code=AQAvrMn9h2jdZL9jqKS5m_FlFSqXqNlDdF7maQ2gaZFQz7zXqGkerD-nBHf4kZSBx0iWe3Qhyf-HxpxMQhfs20SBCFQwo7e965sdVEiWika4IzZzyMX2ai0EtXvaeccYE5OCbyc08y3m-dGwm_Uks13jnaAUliy2tqIqYYPFZqrzwcChuJwv39qL2Cl_n11Nkmity1UeO1EGcrS8sorxP26m with params client_id=280217605XXXXXX&client_secret=4ba259f0f6acfb44dfbe55XXXXXXXXXX&redirect_uri=http%3A%2F%2Fsfmelodydemo.dev%2Ffrontend_dev.php%2Faccess%2Ffacebook&code=AQAvrMn9h2jdZL9jqKS5m_FlFSqXqNlDdF7maQ2gaZFQz7zXqGkerD-nBHf4kZSBx0iWe3Qhyf-HxpxMQhfs20SBCFQwo7e965sdVEiWika4IzZzyMX2ai0EtXvaeccYE5OCbyc08y3m-dGwm_Uks13jnaAUliy2tqIqYYPFZqrzwcChuJwv39qL2Cl_n11Nkmity1UeO1EGcrS8sorxP26m | GET
Nov 29 21:06:27 symfony [err] {OAuth} access token failed - facebook returns Array
(
)

Nov 29 21:06:27 symfony [info] {OAuth} call https://graph.facebook.com/me with params |
Nov 29 21:06:28 symfony [info] {OAuth} call https://graph.facebook.com/me with params |
```

It all goes wrong after this due to the missing token.

Symptoms are very similar to the ones reported by JeJeJeRe in this issue: https://github.com/chok/sfMelodyPlugin/issues/9

He solved it by moving his project to a real online domain. I don't think it should necessarily be the root cause here. Looking at the domain name configured in your project (sfmelodydemo.dev) I suppose you are also using a virtual environment. Can you please confirm that? Any other help with setting up the demo would be appreciated.

Thanks in advance.