Kdyby / Facebook

[DEPRECATED] Use https://github.com/thephpleague/oauth2-facebook instead
Other
42 stars 36 forks source link

Graph Api 2.4 ('/me') returns name and id only #41

Open flexroad opened 9 years ago

flexroad commented 9 years ago

I have setup new Facebook app and it is under the api version 2.4. When I call php $fb->api('/me'); it returns name and id only... What I need is email as well. Any ideas?

All works perfectly with 2.0 and 2.2 (other fb apps I'm using)

fprochazka commented 9 years ago

@flexroad you probably have to ask for the permissions in the app settings in developer console in facebook.

fprochazka commented 9 years ago

If it's a bug of this extension, please reopen.

flexroad commented 9 years ago

As I said... When I use different facebook app (v 2.2) (I have changed appId and 51a76f436572195b41550af7a21fb84d) all works perfectly.

I looks like some incompatibility between current kdyby/facebook and facebook graph api v2.4.

fprochazka commented 9 years ago

Kdyby is not changing any responses, it just returns what it gets from the api

fprochazka commented 9 years ago

I have very little time to investigate this right now. Can you debug it please?

flexroad commented 9 years ago

I have no idea how to do that. :( Any article about "debug it please"? Cheers.

fprochazka commented 9 years ago

@flexroad In czech https://filip-prochazka.com/blog/debuggujeme-s-phpstormem, english http://blog.jetbrains.com/phpstorm/2015/03/debugging-with-phpstorm/

davidkrmela commented 9 years ago

I think that Kdyby\Facebook\Facebook::api behaves correctly. If you want email in v2.4, you should call:

$fb->api('/me', NULL, ['fields' => 'email']);

But there is problem with Kdyby\Facebook\Profile::getDetails that does not return required field. Temporary fix could be, for example:

public function getDetails($key = NULL)
{
    if ($this->details === NULL) {
        try {
            $this->details = $this->facebook->api('/' . $this->profileId);

        } catch (FacebookApiException $e) {
            $this->details = array();
        }
    }

    if ($key !== NULL) {
        if (!array_key_exists($key, $this->details)) {
            try {
                $fields = $this->facebook->api('/' . $this->profileId, NULL, ['fields' => $key]);
                $this->details[$key] = isset($fields[$key]) ? $fields[$key] : NULL;

            } catch (FacebookApiException $e) {
                $this->details[$key] = NULL;
            }
        }
        return isset($this->details[$key]) ? $this->details[$key] : NULL;
    }

    return $this->details;
}
davidkrmela commented 9 years ago

see Declarative Fields @ https://developers.facebook.com/docs/apps/changelog#v2_4

JakubTN commented 9 years ago

@davidkrmela your example didn't work for me. For me, only little modification in request call helped:

$me = $fb->api('/me?fields=id,first_name,last_name,picture,email');

I have to specify requested fields right after /me string and everything works fine. Statement with fields specified as 3rd param of ->api method didn't work for me.

davidkrmela commented 9 years ago

@JakubTN that's strange. On master, I just tried:

$me = $fb->api('/me', NULL, ['fields' => [
    'id',
    'first_name',
    'last_name',
    'picture',
    'email',
]]);

and gives me same result.

JakubTN commented 9 years ago

@davidkrmela I'm using 2.0.0., maybe that's the reason.

ilian6806 commented 7 years ago

Since v2.4 , the graph API requires that you explicitly request the field(s) you need for your GET requests. You can see the change log.

iad24 commented 7 years ago

Now Im not getting the email I have developed my facebook login function like 1 year ago and it was working before. Im already using API 2.4, pod is 4.9.1. Then suddenly all platforms not working (android, ios, web)

For iOS, i have it this way:

let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id,email,name"], tokenString: tokenString, version: nil, HTTPMethod: "GET")
        req.startWithCompletionHandler({ (connection, result, error : NSError!) -> Void in
            SGLogger.logDebug("result=\(result), error=\(error)")

I am already putting 'email' in the fields. Anyone having this issue lately???

jaiswarvipin commented 7 years ago

One of the my friend was trying to the issue from last 5 days. huummm very irritating. which got love in 2 min...

Assumption: using PHP for O2Authentication Solution:

$loginURL = $fb->getLoginUrl({your redirect URL},['email']);

And job is done.

Thanks & Regards Jaiswar Vipin Kumar R.

sergeylukin commented 6 years ago

Came here because had same problem with Javascript SDK, unrelated to Nette project, and your inputs guys helped me, indeed had to pass ?fields explicitely in /me request in order to get email and other values, more details in Facebook SDK v.2.4 changelog

developer11 commented 5 years ago

One of the my friend was trying to the issue from last 5 days. huummm very irritating. which got love in 2 min...

Assumption: using PHP for O2Authentication Solution:

$loginURL = $fb->getLoginUrl({your redirect URL},['email']);

And job is done.

Thanks & Regards Jaiswar Vipin Kumar R.

thanks man