PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label laravel-socialite. Show all posts
Showing posts with label laravel-socialite. Show all posts

Friday, February 4, 2022

[FIXED] Class App\Http\Controllers\SocialFacebookAccountService does not exist error in laravel

 February 04, 2022     facebook, facebook-php-sdk, laravel, laravel-socialite, php     No comments   

Issue

I am using Socialite for Logging in my users with Facebook. I have done all the processes needed to built the functionality. When I click on "Login with Facebook", it asks for permission and giving permissions on facebook, it redirects me too an error.

This is the error link: http://localhost:8888/under_dev/mytaswir/public/callback?code=AQDupltbruPf7MokV6N-Mlmrcmqu-QFeKyImrMz8Yp3ViAv128lZBDfPS88Su1q60o6EfFL0_KIy2YH7lztGJrdj0ZDUFZDjR2ucMobLpUGyzPc39ABElZBJko3llqB5xehmZxJMuay7lBHybZ7F6AMxrCN2H0bNhPFPts5_v6Zmb0kfFR7H2A-ha4EXbJzTX6Y98SY9G50HWP1v-KqcUt5ozXfsNIldR19O_dMCEunGLTsf2sKLK76ObEwPdERhW-XzhJv-IdzeHU-Ppw91TWYHjWvBbEajwQH9N-p91VjWNaede7zOKfCBYUiOedzlLRDfz1qv9QghjmceULRk-DwldD0hY1nBv_jSJwVtq_FLhQ&state=UkCIOpg6dqle5dStyvbgtc9se0OiLxGwqWUZyTli#=

This is the error screenshot: It gives out an error: **Class App\Http\Controllers\SocialFacebookAccountService does not exist** It gives out an error: **Class App\Http\Controllers\SocialFacebookAccountService does not exist!

I have made all my Controllers, Service Providers, Aliases, etc.. in the way suggested on this article.

Please help me get rid of this error. I want the programme to log in my Facebook User into the dashboard.

If you want to see the files, see this git commit.

Thanks in advance.


Solution

I think you are missing the namespace here: https://github.com/KumarAbhirup/myTaswir/blob/c07b2b5a3dd38f70dd0f26eed2eeb983469993ab/app/Http/Controllers/SocialAuthFacebookController.php#L26

  /**
   * Return a callback method from facebook api.
   *
   * @return callback URL from facebook
   */
  public function callback(SocialFacebookAccountService $service)

This method belongs to App\Http\Controllers\SocialAuthFacebookController, so when the system tries to resolve the class name SocialFacebookAccountService from that "location", it will result in App\Http\Controllers\SocialFacebookAccountService, and that does not exist.

The class is actually in the namespace \App\Services, so you must also use that in this place:

  public function callback(\App\Services\SocialFacebookAccountService $service)

Edit: Fixed error regarding missing leading \, to refer the fully qualified namespace



Answered By - CBroe
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Input Facebook Data (Gender, Birthdate, Address and Bio) into database with Laravel Socialite

 February 04, 2022     facebook-graph-api, facebook-php-sdk, laravel, laravel-socialite, php     No comments   

Issue

I have created a complete code which allows Facebook Login by getting Name, Email and Avatar of the user in the database by using Laravel Socialite.

I did it by writing this:

$user = User::create([
                'email' => $providerUser->getEmail(),
                'name' => $providerUser->getName(),
                'avatar' => $providerUser->getAvatar(),
                'password' => md5(rand(1,10000)),
            ]);

But for putting Gender, BirthDate and Address in the database, I tried this.

$user = User::create([
                'email' => $providerUser->getEmail(),
                'name' => $providerUser->getName(),
                'avatar' => $providerUser->getAvatar(),
                'gender' => $providerUser->getGender(),
                'bio' => $providerUser->getBio(),
                'password' => md5(rand(1,10000)),
            ]);

But, there are no functions such as getGender() or getBio(). Do you know what they are?

I have also asked necessary permissions to Facebook Driver in SocialController.php

public function redirect()
  {
      return Socialite::driver('facebook')->fields([
        'first_name', 'last_name', 'email', 'gender', 'birthday'
        ])->scopes([
            'email', 'user_birthday'
        ])->redirect();
  }

All necessary stuffs like Database Tables, Migrations, Models and a working project without Gender and Bio is ready. But I need to add more info in database. How can I do so?

I search such questions already on StackOverflow but didn't find a satisfying answer. I hope someone answers this.

Thank you in advance.


Solution

Default socialite provider for Facebook does not have the method to get gender & bio.

For more info, You can check the available methods here:

https://github.com/laravel/socialite/blob/3.0/src/Contracts/User.php https://github.com/laravel/socialite/blob/3.0/src/AbstractUser.php

This StackOverflow might help you:

How to get birthday gender and religion information using laravel socialite implementing facebook Api

Apart from getting the scope in redirect you also need to pass them in call back

 public function handleFacebookCallback()
{
    $facebook_user = Socialite::driver('facebook')->fields([
        'first_name', 'last_name', 'email', 'gender', 'birthday'
    ])->user();
}

Check available helper methods

https://github.com/laravel/socialite/blob/3.0/src/AbstractUser.php

  • offsetExists('gender')
  • offsetGet('gender')

These methods can help get extra info from users array



Answered By - Ajit Bohra
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, January 3, 2022

[FIXED] Facebook - Invalid Scopes: manage_pages , publish_pages when my app in live mode

 January 03, 2022     facebook-graph-api, facebook-login, facebook-php-sdk, laravel-socialite     No comments   

Issue

I am using Laravel version 5.8 and I am using Laravel Sociallite plugin to connect users with Facebook.

Now I want to get pulbish_pages and manage_pages access so that I can post on my Facebook page.

I have tried following code:

public function redirectToProvider() {
    return Socialite::with('facebook')->scopes(['manage_pages','publish_pages'])->redirect();
}

Now when I click on login with the Facebook button it shows error like:

Invalid Scopes: manage_pages,publish_pages. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: https://developers.facebook.com/docs/facebook-login/permissions

enter image description here


Solution

https://developers.facebook.com/docs/apps/review/

You have to get those permissions approved by Facebook before you can go live with your App. Without approval, they will only work for users with a role in the App.



Answered By - andyrandy
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, December 29, 2021

[FIXED] Retrieving facebook user access token with socialite on laravel 5.4

 December 29, 2021     facebook, facebook-graph-api, laravel, laravel-socialite, php     No comments   

Issue

I am trying to get user access token so I can send CURL request through Guzzle to Facebook's Graph API to get user's friends that are using the app. But I can't seem to be able to obtain it. Here's my controller:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use Socialite;

class SocialFriendsController extends Controller
{

    public function getFacebookFriends()
    {

    $user = Socialite::driver('facebook')->user();
    $access_token = $user->token;

    $client = new Client();
    $body = $client->get('https://graph.facebook.com/v2.11/me/friends', [
        'query' => [
            'access_token' => '$access_token',
        ]
    ])->getBody();

        $result = \GuzzleHttp\json_decode($body, 1);
    return view('pages.admin.posts.create', ['result' => $result]);
   }

}

Solution

A couple of things to note. First of all, the following part of your code won't work the way you expect it to:

'access_token' => '$access_token',

You're trying to do variable interpolation, which doesn't work when you use single quotes ('). You should use double quotes ("$access_token") instead, or since you're not actually doing anything else with that string, you could just remove the quotes altogether.

Secondly, when doing Facebook logins (In your case, using Socialite) the access token you receive from Facebook is single use (I think so anyway - at least from my own experience). When you do Socialite::driver('facebook')->user(), Socialite is actually using the access token to grab the user object. If you attempt to use it again, Facebook will return an error.

Socialite is probably not the way to go to achieve what you're trying to do. I would suggest using the Facebook SDK directly to get what you're after.



Answered By - Jonathon
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing