Custom Connection for Pinterest

I have almost got a Customer Connection to Pinterest up and running, but falling at the final hurdle.

What I get back from Pinterest looks like this …

“data”: {
“url”: “https://www.pinterest.com/Bob0413/”,
“first_name”: “Bob”,
“last_name”: “Smith”,
“id”: “583405231670497967”

My Fetch User Profile Script looks like this …

function(accessToken, ctx, cb) {
request.get(‘https://api.pinterest.com/v1/me/’, {
headers: {
‘Authorization’: 'Bearer ’ + accessToken
}
}, function(e, r, b) {
if (e) return cb(e);
if (r.statusCode !== 200) return cb(new Error('StatusCode: ’ + r.statusCode));
var profile = JSON.parse(b);
cb(null, {
user_id: profile.id,
family_name: profile.last_name,
given_name: profile.first_name
});
});
}

But doesn’t appear to be working, as the user_id is not getting set to the id.

Also in my Rule that stores the tokens, I am getting the provider come across as “oauth2” so it is difficult to have a rule just to Pinterest.

Any clues ? It feels like I am almost there. Thanks.

I will answer my own question …

user_id: profile.id,
family_name: profile.last_name,
given_name: profile.first_name

needs to be …

  user_id: profile.data.id,
  family_name: profile.data.last_name,
  given_name: profile.data.first_name

This still leaves me with the issue of how to get the access token from Pinterest into the app meta_data.