Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: defined property: stdClass::$id #101

Open
sts-ryan-holton opened this issue Dec 4, 2023 · 2 comments
Open

Bug: defined property: stdClass::$id #101

sts-ryan-holton opened this issue Dec 4, 2023 · 2 comments

Comments

@sts-ryan-holton
Copy link

👋 Hi,

Just reaching out as I've identified a problem with the getReceiver function, firstly, not quite sure why I'm getting the error in the first place, I'm using v8.0.0 of the package, getting the error:

ErrorException: Undefined property: stdClass::$id in /var/www/domain-monitor-api/vendor/laravel-notification-channels/twitter/src/TwitterDirectMessage.php:45

Presumably the error handling of the $user->id here needs to be more robust?

/**
 * Get Twitter direct message receiver.
 *
 * @return string|mixed
 *
 * @throws CouldNotSendNotification
 */
public function getReceiver(TwitterOAuth $twitter): mixed
{
    if (is_int($this->to)) {
        return $this->to;
    }

    $user = $twitter->get('users/show', [
        'screen_name' => $this->to,
        'include_user_entities' => false,
        'skip_status' => true,
    ]);

    if ($twitter->getLastHttpCode() === 404) {
        throw CouldNotSendNotification::userWasNotFound($twitter->getLastBody());
    }

    return $user->id;
}
@christophrumpel
Copy link
Collaborator

Hey. thanks for info. Can you check what "$user" contains? Looks like it is not null?

Greets

@sts-ryan-holton
Copy link
Author

sts-ryan-holton commented Dec 6, 2023

I get the following error back on the $user variable:

{
   "user":{
      "stdClass":{
         "errors":[
            {
               "message":"You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/portal/product",
               "code":453
            }
         ]
      }
   }
}

This is how I want to send a message

/**
 * Get the Twitter representation of the notification.
 *
 * @param  mixed  $notifiable
 */
public function toTwitter($notifiable)
{
    $userIntegration = $this->getUserIntegration($notifiable->id, 'twitter');

    if (! $userIntegration) {
        exit;

        return [];
    }

    try {
        $this->createHistoryEntry('twitter', 'Monitor Test Notification', [], $notifiable);
    } catch (\Exception $e) {
    }

    return new TwitterDirectMessage($userIntegration->schema->twitter_username, "This is your monitor test notification!");
}

$userIntegration->schema->twitter_username returns the twitter username, without the @ symbol.

I have the following permissions:

Created with Read, Write, and Direct Messages permissions

And I'm on the free plan for the api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants