4

I have used below code, it's working in Magento-2.2 but not working in Magento-2.1 after code compilation.

public function __construct(
        \OAuth\Common\Consumer\CredentialsFactory $credentialsFactory
    ) {
        $this->credentialsFactory = $credentialsFactory;
    }

    public function execute()
    {
       $credentials = $this->credentialsFactory->create([
        'consumerId' => $this->helper->getConsumerId('facebook'),
        'consumerSecret' => $this->helper->getConsumerSecret('facebook'),
        'callbackUrl' => $this->helper->getAuthUrl('facebook')
        ]);
    }

if I deleted var/di & var/generation it's working, if I compiled code in 2.1.x then it's throw below error.

Exception #0 (Exception): Warning: Missing argument 2 for OAuth\Common\Consumer\Credentials::__construct(), called in /var/www/html/magento-2.1.11-demo/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93 and defined in /var/www/html/magento-2.1.11-demo/vendor/lusitanian/oauth/src/OAuth/Common/Consumer/Credentials.php on line 30

0 /var/www/html/magento-2.1.11-demo/vendor/lusitanian/oauth/src/OAuth/Common/Consumer/Credentials.php(30):

Magento\Framework\App\ErrorHandler->handler(2, 'Missing argumen...', '/var/www/html/m...', 30, Array)

1 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(93):

OAuth\Common\Consumer\Credentials->__construct(Object(Magento\Framework\ObjectManager\ObjectManager))

2 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('OAuth\Common\Co...',

Array)

3 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/ObjectManager/ObjectManager.php(57):

Magento\Framework\ObjectManager\Factory\Compiled->create('OAuth\Common\Co...', Array)

4 /var/www/html/magento-2.1.11-demo/var/generation/OAuth/Common/Consumer/CredentialsFactory.php(43): Magento\Framework\ObjectManager\ObjectManager->create('OAuth\Common\Co...',

Array)

5 /var/www/html/magento-2.1.11-demo/app/code/Magedelight/ModuleName/Controller/Facebook/Login.php(84):

OAuth\Common\Consumer\CredentialsFactory->create(Array)

6 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/App/Action/Action.php(102):

Magedelight\ModuleName\Controller\Facebook\Login->execute()

7 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))

8 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(70): Magedelight\ModuleName\Controller\Facebook\Login\Interceptor->___callParent('dispatch',

Array)

9 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magedelight\Soc...',

'dispatch', Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor), Array, 'contextPlugin')

10 /var/www/html/magento-2.1.11-demo/vendor/magento/module-store/App/Action/Plugin/Context.php(106):

Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Request\Http))

11 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\Action\Plugin\Context->aroundDispatch(Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor),

Object(Closure), Object(Magento\Framework\App\Request\Http))

12 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magedelight\Soc...',

'dispatch', Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor), Array, 'customer-app-ac...')

13 /var/www/html/magento-2.1.11-demo/vendor/magento/module-customer/Model/App/Action/ContextPlugin.php(61):

Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Request\Http))

14 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Customer\Model\App\Action\ContextPlugin->aroundDispatch(Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor),

Object(Closure), Object(Magento\Framework\App\Request\Http))

15 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magedelight\Soc...',

'dispatch', Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor), Array, 'storeCheck')

16 /var/www/html/magento-2.1.11-demo/vendor/magento/module-store/App/Action/Plugin/StoreCheck.php(44):

Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Request\Http))

17 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\Action\Plugin\StoreCheck->aroundDispatch(Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor),

Object(Closure), Object(Magento\Framework\App\Request\Http))

18 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magedelight\Soc...',

'dispatch', Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor), Array, 'weee-app-action...')

19 /var/www/html/magento-2.1.11-demo/vendor/magento/module-weee/Model/App/Action/ContextPlugin.php(112):

Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Request\Http))

20 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Weee\Model\App\Action\ContextPlugin->aroundDispatch(Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor),

Object(Closure), Object(Magento\Framework\App\Request\Http))

21 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Interceptor.php(138):

Magento\Framework\Interception\Chain\Chain->invokeNext('Magedelight\Soc...', 'dispatch', Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor), Array, 'tax-app-action-...')

22 /var/www/html/magento-2.1.11-demo/vendor/magento/module-tax/Model/App/Action/ContextPlugin.php(91):

Magedelight\ModuleName\Controller\Facebook\Login\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http))

23 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Interceptor.php(142):

Magento\Tax\Model\App\Action\ContextPlugin->aroundDispatch(Object(Magedelight\ModuleName\Controller\Facebook\Login\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))

24 /var/www/html/magento-2.1.11-demo/var/generation/Magedelight/ModuleName/Controller/Facebook/Login/Interceptor.php(26):

Magedelight\ModuleName\Controller\Facebook\Login\Interceptor->___callPlugins('dispatch', Array, Array)

25 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/App/FrontController.php(55):

Magedelight\ModuleName\Controller\Facebook\Login\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))

26 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))

27 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch',

Array)

28 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...',

'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'requestPreproce...')

29 /var/www/html/magento-2.1.11-demo/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94):

Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Request\Http))

30 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor),

Object(Closure), Object(Magento\Framework\App\Request\Http))

31 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...',

'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')

32 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69):

Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Request\Http))

33 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor),

Object(Closure), Object(Magento\Framework\App\Request\Http))

34 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...',

'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')

35 /var/www/html/magento-2.1.11-demo/vendor/magento/module-page-cache/Model/App/FrontController/VarnishPlugin.php(55):

Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain{closure}(Object(Magento\Framework\App\Request\Http))

36 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor),

Object(Closure), Object(Magento\Framework\App\Request\Http))

37 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Interceptor.php(138):

Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')

38 /var/www/html/magento-2.1.11-demo/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73):

Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http))

39 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/Interception/Interceptor.php(142):

Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))

40 /var/www/html/magento-2.1.11-demo/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26):

Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)

41 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/App/Http.php(135):

Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))

42 /var/www/html/magento-2.1.11-demo/vendor/magento/framework/App/Bootstrap.php(258):

Magento\Framework\App\Http->launch()

43 /var/www/html/magento-2.1.11-demo/index.php(41): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))

44 {main}

How I can resolve this issue for Magento-2.1.x? Any one have solution or idea?

3
  • can you please share your error log file code?
    – Abdul
    Commented Apr 12, 2018 at 12:48
  • Check my updated question Commented Apr 12, 2018 at 12:54
  • @SureshChikani Magento ver 1.9.2.3,I am work with REST API in POSTMAN, i have all oAuth 1.0 details like Consumer Key,Consumer Secret,Access Token,Token Secret. Now i moved to oAuth 2.0, how can i get my all oAuth 2.0 details?
    – zus
    Commented Oct 30, 2018 at 6:42

1 Answer 1

0

Try below,

<?php
use OAuth\Common\Consumer\Credentials;

class Yourclassname
{
    public function execute()
    {
        $credentials = new Credentials($this->helper->getConsumerId('facebook'), $this->helper->getConsumerSecret('facebook'), $this->helper->getAuthUrl('facebook'));
    }

}

Reference from,

vendor/magento/magento2-base/dev/tests/api-functional/framework/Magento/TestFramework/Authentication/OauthHelper.php
3
  • as per above code, without array how can pass array argument? Commented Apr 12, 2018 at 10:32
  • @SureshChikani Please check updated answer. Commented Apr 12, 2018 at 10:38
  • I already check this reference but As per magento marketplace standards we cannot instantiate object of class as above. Commented Apr 12, 2018 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.