hi there
am working on node and i face a problem with code400 (bad request)
am using this

async function follow(oauthToken, tokenSecret) {

 let optio = { 

   'user_id': '2244994945',

   'follow':'true'

};

 let methUrl = 'https://api.twitter.com/1.1/friendships/create.json?user_id=2244994945&follow=true' ;

 let baseUrl = 'https://api.twitter.com/1.1/friendships/create.json'

 let methodType='POST'

 var tt = await sendRequest.postReq(methodType,methUrl , baseUrl, oauthToken , tokenSecret , optio) ;

 return tt

}


and it call this

async function postReq(method, TheUrl , baseUrl ,oauthToken,tokenSecret,opt){

    try{

      const re = await axios.post(TheUrl,{

        headers:{

        'authorization' : operation.getHeader(baseUrl,method,oauthToken,tokenSecret,opt),

        'Content-type' : 'application/json'

      }});

      return re ;

    }catch(error){console.log(error);}

    }

am useing ( operation.getHeader) with deferent method (Get friend id)and it work fine
Even so I try to generate the signature manually and its the same so i dont think that what causing the problem any idea where could be the problem ?!

one more thing
in (POST friendships/create | Docs | Twitter Developer Platform)

what is the meaning of this( Requires authentication? Yes (user context only) )?

thanks

This means that your Auth must include the user account token and secret for the account you want to follow from. You seem to be talking about generating your own Auth headers, I would encourage you to use a known library that does this automatically; not because i want you NOT to do the coding, but because it is tricky and other people have done it before.

1 Like

In addition to what Andy mentioned, you’re also missing an ampersand between the numerical ID and the word follow in the request URL:

user_id=2244994945&follow=true

hi and thanks for responding
so what the difference i mean so far every request In 1.1 i have to use account token and token secret to get for example an id for a user . is there is a difference here ?

that was my bad when i copy the code from the vs sorry

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.