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

GET statuses/mentions_timeline #10

Closed
soderlind opened this issue Nov 5, 2013 · 2 comments
Closed

GET statuses/mentions_timeline #10

soderlind opened this issue Nov 5, 2013 · 2 comments

Comments

@soderlind
Copy link

Not an issue, more a wish: Do you plan to add support for GET statuses/mentions_timeline ?

@soderlind
Copy link
Author

This (hack) works. I haven't added the option to choose if you want to add mentions, here you'll get them if you want them or not:

private function _date_compare($a, $b) {
    $acreated = strtotime($a->created_at);
    $bcreated = strtotime($b->created_at);

    if ($acreated == $bcreated) {
         return 0;
    }
    return ($acreated > $bcreated) ? -1 : 1;    
}

public function parseFeed( $widgetOptions ) {
    $parameters = $this->_get_feed_request_settings( $widgetOptions );
    $response = array();
    $user_timeline = array();
    $mentions_timeline = array();

    if ( ! empty( $parameters['screen_name'] ) ) {
        if ( empty( $this->_settings['twp-authed-users'][strtolower( $parameters['screen_name'] )] ) ) {
            if ( empty( $widgetOptions['errmsg'] ) )
                $widgetOptions['errmsg'] = __( 'Account needs to be authorized', $this->_slug );
        } else {
            $this->_wp_twitter_oauth->set_token( $this->_settings['twp-authed-users'][strtolower( $parameters['screen_name'] )] );
            /*
             START MODIFICATION
             */
            $user_timeline = $this->_wp_twitter_oauth->send_authed_request( 'statuses/user_timeline', 'GET', $parameters );
            $mentions_timeline = $this->_wp_twitter_oauth->send_authed_request( 'statuses/mentions_timeline', 'GET', $parameters );

            if ( ! is_wp_error( $user_timeline ) && ! is_wp_error( $mentions_timeline )) {
                $response = array_merge_recursive($user_timeline,$mentions_timeline);
                usort($response,array($this,"_date_compare")); // sort on created_at,
                return $response;
            }
            /*
            END MODIFICATION
             */
        }
    } elseif ( ! empty( $parameters['list_id'] ) ) {
        $list_info = explode( '::', $widgetOptions['list'] );
        $user = array_shift( $list_info );
        $this->_wp_twitter_oauth->set_token( $this->_settings['twp-authed-users'][strtolower( $user )] );

        $response = $this->_wp_twitter_oauth->send_authed_request( 'lists/statuses', 'GET', $parameters );
        if ( ! is_wp_error( $response ) )
            return $response;
    }

    if ( empty( $widgetOptions['errmsg'] ) )
        $widgetOptions['errmsg'] = __( 'Invalid Twitter Response.', $this->_slug );
    do_action( 'widget_twitter_parsefeed_error', $response, $parameters, $widgetOptions );
    throw new Exception( $widgetOptions['errmsg'] );
}

@soderlind
Copy link
Author

Please see #11

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

1 participant