Urgent help require- System.HttpResponse[Status=Bad Request, StatusCode=400]

restapi
oauth
api

#1

Hi Everyone, I am using following code to get tweets “only tweets”, but getting error:

string access_token;
string tweets;
String keyencoded = EncodingUtil.urlEncode('CYXp886M6g04xwouOHLYg4UJf','UTF-8');
	String secretkeyencoded = EncodingUtil.urlEncode('5qC4A3JZDF8you0VtKx95AJqROlXi2oihTkJgVNNsv8pVQ2cjT', 'UTF-8');
	String sFinal = keyencoded + ':' + secretkeyencoded;
	Blob headerValue = Blob.valueOf(sFinal);
	HttpRequest req = new HttpRequest();
    req.setEndpoint('https://api.twitter.com/oauth2/token');
    req.setMethod('POST');
    String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
    req.setHeader('Authorization', authorizationHeader);
    req.setBody('grant_type=client_credentials');
    Http http = new Http();
    HTTPResponse res = http.send(req);

    JSONParser parser = JSON.createParser(res.getBody());
    while(parser.nextToken() != null)
    {
        if(parser.getCurrentToken() == JSONToken.FIELD_NAME)
        {
            String fieldName = parser.getText();
            parser.nextToken();
            if(fieldName == 'access_token')
            {
                access_token = parser.getText();
            }

        }
    }
	
	Http http1 =new Http();
	HttpRequest request=new HttpRequest();
	request.setEndpoint('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=virendersehwag');
	request.setMethod('GET');
	string authorizationHeader1 ='Bearer'+access_token;
	request.setHeader('Authorization',authorizationHeader1);
	HTTPResponse response=http1.send(request);
	if(response.getStatusCode()==200)
	{
	Map<string,object>results=(Map<string, Object>)JSON.deserializeUntyped(response.getBody());
	List<object>a=(List<object>)results.get('text');
	system.debug(results);
	system.debug(a);
	}

#2

What error are you seeing?