source/php/Module/Social/Feed.php
public function getTwitterAccessToken()
    {
        $consumer_key    = urlencode($this->args['api_user']);
        $consumer_secret = urlencode($this->args['api_secret']);

        // Concatenate key and secret and base64 encode
        $bearer_token = $consumer_key . ':' . $consumer_secret;
        $base64_bearer_token = base64_encode($bearer_token);

        // Request access token
        $endpoint = 'https://api.twitter.com/oauth2/token';

        // Request headers
        $headers = array(
            "POST /oauth2/token HTTP/1.1",
            "Host: api.twitter.com",
            "User-Agent: jonhurlock Twitter Application-only OAuth App v.1",
            "Authorization: Basic " . $base64_bearer_token,
            "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
        );

        // Postdata
        $data = array(
            'grant_type' => 'client_credentials'
        );

        // Curl and format response
        $curl = new \Modularity\Helper\Curl();
        $response = $curl->request('POST', $endpoint, $data, null, $headers);
        $response = json_decode($response);

        if (isset($response->errors)) {
            return $response;
        }

        return $response->access_token;
    }
public function getTwitterAccessToken()
    {
        $consumer_key    = urlencode($this->args['api_user']);
        $consumer_secret = urlencode($this->args['api_secret']);

        // Concatenate key and secret and base64 encode
        $bearer_token = $consumer_key . ':' . $consumer_secret;
        $base64_bearer_token = base64_encode($bearer_token);

        // Request access token
        $endpoint = 'https://api.twitter.com/oauth2/token';

        // Request headers
        $headers = array(
            "POST /oauth2/token HTTP/1.1",
            "Host: api.twitter.com",
            "User-Agent: jonhurlock Twitter Application-only OAuth App v.1",
            "Authorization: Basic " . $base64_bearer_token,
            "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
        );

        // Postdata
        $data = array(
            'grant_type' => 'client_credentials'
        );

        // Curl and format response
        $curl = new \Modularity\Helper\Curl();
        $response = $curl->request('POST', $endpoint, $data, null, $headers);
        $response = json_decode($response);

        if (isset($response->errors)) {
            return $response;
        }

        return $response->access_token;
    }
public function getTwitterAccessToken ( ) { $ consumer_key = urlencode ( $ this -> args [ 'api_user' ] ) ; $ consumer_secret = urlencode ( $ this -> args [ 'api_secret' ] ) ; // Concatenate key and secret and base64 encode $ bearer_token = $ consumer_key . ':' . $ consumer_secret ; $ base64_bearer_token = base64_encode ( $ bearer_token ) ; // Request access token $ endpoint = 'https://api.twitter.com/oauth2/token' ; // Request headers $ headers = array ( "POST /oauth2/token HTTP/1.1" , "Host: api.twitter.com" , "User-Agent: jonhurlock Twitter Application-only OAuth App v.1" , "Authorization: Basic " . $ base64_bearer_token , "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" ) ; // Postdata $ data = array ( 'grant_type' => 'client_credentials' ) ; // Curl and format response $ curl = new \ Modularity \ Helper \ Curl ( ) ; $ response = $ curl -> request ( 'POST' , $ endpoint , $ data , null , $ headers ) ; $ response = json_decode ( $ response ) ; if ( isset ( $ response -> errors ) ) { return $ response ; } return $ response -> access_token ; }
Get Twitter Access Token
@return string Access token
Get Twitter Access Token