Can't link an existing account to twitter.

Created on 13 December 2021, over 2 years ago
Updated 30 October 2023, 8 months ago

Cannot authenticate or link an account so it can post to twitter

Errors:

Notice: Undefined property: stdClass::$id in Drupal\social_post_twitter\Controller\TwitterPostController->callback() (line 187 of modules/contrib/social_post_twitter/src/Controller/TwitterPostController.php).
Notice: Undefined property: stdClass::$name in Drupal\social_post_twitter\Controller\TwitterPostController->callback() (line 188 of modules/contrib/social_post_twitter/src/Controller/TwitterPostController.php).
Notice: Undefined property: stdClass::$id in Drupal\social_post_twitter\Controller\TwitterPostController->callback() (line 188 of modules/contrib/social_post_twitter/src/Controller/TwitterPostController.php).
Notice: Undefined property: stdClass::$url in Drupal\social_post_twitter\Controller\TwitterPostController->callback() (line 188 of modules/contrib/social_post_twitter/src/Controller/TwitterPostController.php).
You could not be authenticated, please contact the administrator.

LOG :

1- Failed to to query entity. Exception: Query condition 'social_post.provider_user_id IN ()' cannot be empty.
2- Failed to add user record in Social Auth entity. Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'provider_user_id' cannot be null: INSERT INTO "social_post" ("uuid", "user_id", "plugin_id", "provider_user_id", "name", "token", "additional_data", "link__uri", "link__title", "link__options") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => ef8ff318-fe0a-4fb0-957f-80f291c3351b [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => social_post_twitter [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => NjRrY3lDcVJSSG5RUEwwMm1qdWtiNUVaYTdXMldrWERydlJlcUJKQUM2TmRBSis1M1JHaW1hemNDMDhRM1hjQ3RyZmFYWVl0cExqSTZPa0FlWUpsZTZXcXBabDlUQ0NzM0pmZUE0aTZLL1F4OTVzNkNzdGpQL0l6eS9ZZlhmc1VqdUk1Vk1YYVlKQzZxRDB4cktRNW5RUERLWDVnMHBtMTkzdkVmclZhUHF1T1FMWWVFME9wdGpia21VTVV3Y3JFbnBWRnpoMzcrUk9ianhrcVFjcklUM2FzWUNzTFNyNSt6SWN3b3B5TzErZ1Z4aURzMUJTeitJT2tiMmYwYWxLUTo6FoXzRM3TTduu1jzqWKAuNA== [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => N; )

Steps to reproduce

  • - PHP 7.4.25
  • - 10.4.21-MariaDB-1
  • - Drupal : Drupal core 9.3.0
  • - Social Auth : 3.x-dev
  • - Social Post : 3.x-dev
  • - Social Post Twitter : 3.0.0-beta2 (since dev failed sql PASS) (but tried both, beta2 and dev).
  • - Key / Secret added properly
  • - Callback URL added on twitter dashboard
  • - 3-legged OAuth is enabled on twitter dashboard

Image Steps:

1-
2-
3-

I understand that this issue is tied to 2 other modules (Social post & Social Auth) but wondering where i can start debugging this properly.

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Hi Wells,

    I am having a similar problem.

    First of all it was not clear to me that the account has to be linked via the user account edit page but when doing so it seems to authorise ok from X but then I am getting the following error in drupal after twitter seems to have returned an access token

    e.g.

    Error message
    Warning: Attempt to read property "id" on null in Drupal\social_post_twitter\Controller\TwitterPostController->callback() (line 187 of modules/contrib/social_post_twitter/src/Controller/TwitterPostController.php).
    Drupal\social_post_twitter\Controller\TwitterPostController->callback()
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    Warning: Attempt to read property "name" on null in Drupal\social_post_twitter\Controller\TwitterPostController->callback() (line 188 of modules/contrib/social_post_twitter/src/Controller/TwitterPostController.php).
    Drupal\social_post_twitter\Controller\TwitterPostController->callback()
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    Warning: Attempt to read property "id" on null in Drupal\social_post_twitter\Controller\TwitterPostController->callback() (line 188 of modules/contrib/social_post_twitter/src/Controller/TwitterPostController.php).
    Drupal\social_post_twitter\Controller\TwitterPostController->callback()
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    Warning: Attempt to read property "url" on null in Drupal\social_post_twitter\Controller\TwitterPostController->callback() (line 188 of modules/contrib/social_post_twitter/src/Controller/TwitterPostController.php).
    Drupal\social_post_twitter\Controller\TwitterPostController->callback()
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    You could not be authenticated, please contact the administrator.

    and

    Type	social_post_twitter
    Date	Friday, October 20, 2023 - 18:27
    User	daniel
    Location	https://streathamlifed8.ddev.site/user/social-post/twitter/auth/callback?oauth_token=KDX8vgAAAAABqj9nAAABi05X79s&oauth_verifier=oOm5OkD5L4nFeByRLCgSr5JOP6xjcPRK
    Referrer	https://api.twitter.com/
    Message	Failed to to query entity. Exception: Query condition 'social_post.provider_user_id IN ()' cannot be empty.
    Severity	Error
    Hostname	192.168.160.10
    
    

    and

    social_post
    Date	Friday, October 20, 2023 - 18:27
    User	daniel
    Location	https://streathamlifed8.ddev.site/user/social-post/twitter/auth/callback?oauth_token=KDX8vgAAAAABqj9nAAABi05X79s&oauth_verifier=oOm5OkD5L4nFeByRLCgSr5JOP6xjcPRK
    Referrer	https://api.twitter.com/
    Message	Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'provider_user_id' cannot be null: INSERT INTO "social_post" ("uuid", "user_id", "plugin_id", "provider_user_id", "name", "token", "additional_data", "link__uri", "link__title", "link__options") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 1f29d6b9-4876-4b99-8a7d-42fa1cc2d1f3 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => social_post_twitter [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => endtMnVDUDlhR1JNWnB3Z3R3MkhVQjFzZDR0TDJqVkYrc2wrRVloc3A3bDUzWXJoWmdYVEdFY3YxYzY0dW5IWW1XVk45Zittb2x5QUhVZC9UdkNYK2tnQjc3Tmo2MVRrVUs0MHFzUHlXVG5pVVRyWGdzdDBUMGduQWRRZjZqWWFWVFNYVjBRa1hEOVRGdzBMTEpnYkdZYzBuaWpnRTBxTTlVMk14a0dGdWRicUVmd1J2eHVVdjJHNjh1Sy94b09yN2tXTjErWFIzTktvSXdzcFAxbER0aXN4UTU2WTIwZVhwUnk5ZkhtZDJ5VDhic0ZKSFpDQmp1NjRFait3MWJXTjo6EzVzjZnSVn9UpONhrPqglg== [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => N; ) in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 43 of /var/www/html/web/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php).
    Severity	Error
    Hostname	192.168.160.10
    Operations	

    and

    social_post_twitter
    Date	Friday, October 20, 2023 - 18:27
    User	daniel
    Location	https://streathamlifed8.ddev.site/user/social-post/twitter/auth/callback?oauth_token=KDX8vgAAAAABqj9nAAABi05X79s&oauth_verifier=oOm5OkD5L4nFeByRLCgSr5JOP6xjcPRK
    Referrer	https://api.twitter.com/
    Message	Failed to add user record in Social Auth entity. Exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'provider_user_id' cannot be null: INSERT INTO "social_post" ("uuid", "user_id", "plugin_id", "provider_user_id", "name", "token", "additional_data", "link__uri", "link__title", "link__options") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 1f29d6b9-4876-4b99-8a7d-42fa1cc2d1f3 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => social_post_twitter [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => endtMnVDUDlhR1JNWnB3Z3R3MkhVQjFzZDR0TDJqVkYrc2wrRVloc3A3bDUzWXJoWmdYVEdFY3YxYzY0dW5IWW1XVk45Zittb2x5QUhVZC9UdkNYK2tnQjc3Tmo2MVRrVUs0MHFzUHlXVG5pVVRyWGdzdDBUMGduQWRRZjZqWWFWVFNYVjBRa1hEOVRGdzBMTEpnYkdZYzBuaWpnRTBxTTlVMk14a0dGdWRicUVmd1J2eHVVdjJHNjh1Sy94b09yN2tXTjErWFIzTktvSXdzcFAxbER0aXN4UTU2WTIwZVhwUnk5ZkhtZDJ5VDhic0ZKSFpDQmp1NjRFait3MWJXTjo6EzVzjZnSVn9UpONhrPqglg== [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => N; )
    Severity	Error
    Hostname	192.168.160.10
    Operations	

    atm I have managed to post tweets with Oauth 1.0 via postman my dev account. I could not figure out how to do this with openauth 2 as was getting a timeout when trying.

    Are you saying that you cannot post tweets with Oauth 2 but you can with v1?

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do
  • πŸ‡ΊπŸ‡ΈUnited States wells Seattle, WA

    Are you saying that you cannot post tweets with Oauth 2 but you can with v1?

    I believe that to be the case. Yes. Even with the latest version of Social Auth Twitter (where things are more up to date) the v2 API is not supported.

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Thanks for the quick response.

    The info on authentication endpoints is here

    https://developer.twitter.com/en/docs/authentication/guides/v2-authentic...

    Info on packages is here

    https://developer.twitter.com/en/docs/twitter-api and
    https://developer.twitter.com/en/docs/twitter-api/getting-started/about-...

    You may be right, but I not see anywhere where it talks about open Auth 2 being restricted by tier.

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Thanks for the tip about https://www.drupal.org/project/social_auth_twitter β†’ . Will check that out.

    This is misleading afaict

    Ensure the app has Elevated Access.

    That should not be necessary as my tests with postman seem to prove.

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Ok I have had a quick look at social_auth_twitter and I am not sure it does what I am looking for.

    I also do like the way this module uses the Rules module.

    This module basically uses abraham/twitteroauth library. To post a new tweet with I can achieve what I want using the following code, even with a basic tier account:

    <?php
    require "vendor/autoload.php";
    
    use Abraham\TwitterOAuth\TwitterOAuth;
    
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
    $content = $connection->get("account/verify_credentials");
    
    // $connection = new TwitterOAuth($ck, $cs, $ot, $os);
    $data =  [
        'text' => 'Hello world local 1'
        ];
    $connection->setApiVersion('2');
    $content = $connection->post("tweets", $data, true);
    echo json_encode($content);

    From what I can see this module currently requires a user to manually login to twitter in order to post etc. I don't really want or need that behaviour.

    What I think I want is to pass access_token and secret. This should be sufficient. I do not want the ability for each user to login. Not really sure why anyone would want that feature?

    Not sure if it can be accomplished here or perhaps I could fork this to achieve what i want, i.e. to post new articles to twitter with a basic tier X account.

  • πŸ‡ΊπŸ‡ΈUnited States wells Seattle, WA

    I didn't mean to imply Social Auth Twitter could be an alternative -- was just pointing out that module is more up-to-date but still only supports the older Twitter API.

    This module should be able to work with a similar process but may or may not need code changes as well.

    I'm happy to review a patch if anyone is able to get things working but I'm not a Twitter user myself so this isn't something I've been able to dig in to.

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Thanks again Wells,

    Just trying to undertand the situation with this module. I think you are saying that it does still work if you have an account with a tier higher than the basic one.

    Perhaps someone who uses X and this module can verify this?

    I would be happy to provide a patch to fix if using a basic tier but my concern here is that any fix could also break things if you have a higher tier subscription.

    Thinking about this further my feeling is my requirements are a little different. From what I can tell this module allows multiple Drupal users to log in to a single Drupal instance and link their respective X accounts, allowing them to post new tweets from a single Drupal instance linked to their unique twitter/x handle.

    My requirement is for a single Drupal user (admin) to link their X account and to post content streams under a single linked X account. At the time of writing up to 1500 posts can be generated on a basic account tier.

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Ok I have created https://www.drupal.org/project/social_post_x β†’ .

    Works a bit differently but to this module but does support a basic tier account.

    One thing I notice is that you I think you need to have an email address associated with your account before being able to post tweets.

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Ok I have now had a chance to look at this issue and from what I can tell this is the failing code:

          // This fails!!!
          $request_token = $client->oauth('oauth/request_token', ['oauth_callback' => $network_plugin->getOauthCallback()]);
    

    in Abraham/TwitterOAuth

    we have

    $result = $this->oAuthRequest($url, 'POST', $parameters);
    
            if ($this->getLastHttpCode() != 200) {
                throw new TwitterOAuthException($result);
            }

    This returns 401 unauthorised. From what I can tell in order to get the oauth2 token, request also needs to pass additional info such as either client id/secret or bearer token.

    To get post access with openAuth2 requires OAuth 2.0 Authorization Code Flow with PKCE.

    https://developer.twitter.com/en/docs/authentication/oauth-2-0

    From what I can tell this requires user to pass some additional data such as client_id and client_secret but I am not absolutely sure on this.

    For my purposes though using OpenAuth 1 seems to be sufficient as I do not need to enable individual users to post from my site.

    Interestingly, in order to configure OpenAuth access an Callback still needs to be added to the X developer panel at the time of writing, even though this is not required afaict for OAuth 1.

Production build 0.69.0 2024