I am looking to grab some information from the data twitter provides. Im looking to extract all the screen names that come out of this object.
T.get('followers/list', { screen_name: 'screenname' }, function (err, data, response) {
console.log(data);
});
You will receive this in the object :
{ users:
[ { id: 1234,
id_str: '1234',
name: 'Name',
screen_name: 'screenName123',
location: '....',
profile_location: null,
description: '....',
url: '...',
entities: [Object],
protected: false,
followers_count: 1751,
friends_count: 2001,
.
.
.
.
. } ] }
How can I abstract just screen_name out of this object. data.users.screen_name returns undefined.
As you can see from the console output, data.users is an array. So if you want the screen_name of the first element then just use: data.users[0].screen_name
Related
Brand new to react-native and typescript!
I'm have a bit of trouble extracting JSON response. I was to extract the response and put it into a class as shown below.
Here is the request code
let notifications: INotification[]
notifications = (await Requests.GET('notification/user/test-user-1', accessToken));
Here is the class
export interface INotification {
id: string;
senderId: string;
receiverId: string;
text: string;
isSeen: boolean;
type: string;
timestamp: string;
}
Here is the Postman response
{
"notifications": [
{
"pk": "user-1",
"sk": "notification1234",
"entity": "notification",
"id": "id number",
"senderId": "test-user-2",
"receiverId": "test-user-1",
"text": "Test notifications",
"isSeen": false,
"type": 2
}
]
}
Here is response from the console
{ notifications:
[ { pk: 'user#test-user-1',
sk: 'notification1234',
entity: 'notification',
id: 'id number',
senderId: 'test-user-2',
receiverId: 'test-user-1',
text: 'Test notifications',
isSeen: false,
type: 2 } ]
}
I want to be able to write out:
console.log("TEXT: ",notifications[0].text )
And get the response of : "Text: Test notifications"
Any help welcome!
the data is in an array you need to pass the array first
console.log("TEXT: ", notifications[0].text);
I have been using the ng2-smart-table template. I could not able to found the location where the data save after click the add new button.some one can help me now.
In this table create data and show in the list the data what we are created. but the case is if we are refresh the browser , the above mentioned data not saved. then what should i do for add those data for firestore.
The DataSource of the mentioned module is simply an array or LocalDataSource object according to Documentation.
Let's take an example.
On typescript file define an array like this.
data = [
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "Sincere#april.biz"
},
{
id: 2,
name: "Ervin Howell",
username: "Antonette",
email: "Shanna#melissa.tv"
},
// ... list of items
{
id: 11,
name: "Nicholas DuBuque",
username: "Nicholas.Stanton",
email: "Rey.Padberg#rosamond.biz"
}
];
settings = {
columns: {
id: {
title: 'ID'
},
name: {
title: 'Full Name'
},
username: {
title: 'User Name'
},
email: {
title: 'Email'
}
},
add:{
confirmCreate:true
},
mode:'inline'
};
On template(html).
<ng2-smart-table (createConfirm)="addData($event)" [settings]="settings"
[source]="data"></ng2-smart-table>
Again on template.
addData(event){
//event.data is the newely created data
// Handle newly created data
// Shape of object is {
// id,
// name,
// username,
// email,
// }
// You must call event.confirm.resolve() to show data on table
}
Above addData(event) function is called when click ctrate confim.
I am trying to translate an object after uploading it but I keep getting 400 Bad Request error.
I am using the forge-api-nodejs-client
here is how my code looks like
var base64 = require('js-base64').Base64;
objectsApi.uploadObject(
bucket.bucketKey,
file.originalname,
file.size,
file.buffer,
{},
oAuth2TwoLegged,
credentials
)
.then(
response => {
const objectDetails = response.body;
// objectId => urn:adsk.objects:os.object:d62db090-0c47-11e8-9a36-7bd06cedf058/Pawn.stl
const job = {
input: {
urn: base64.encode(objectDetails.objectId)
},
output: {
formats: [
{
type: "obj"
}
]
}
};
derivativesApi
.translate(job, {}, oAuth2TwoLegged, credentials)
.then(
data => {
res.send(data);
},
err => {
// it fails here with 400 status error
res.send(err);
}
);
},
err => {
res.send(err);
}
);
my job object looks like this:
{
input:{
urn: 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZDYyZGIwOTAtMGM0Ny0xMWU4LTlhMzYtN2JkMDZjZWRmMDU4L1Bhd24uc3Rs'
},
output: {
formats: [
type: "obj"
]
}
}
the response
{
statusCode: 400,
statusMessage: "Bad Request"
}
I have also a tutorial using the Forge NPM to do the whole process of creating bucket to upload file and translate it. I think the part you are having problems with is the uploading part
Check this https://github.com/jaimerosales/modelderivative-nodejs-tutorial/blob/master/uploader.js#L145
Your payload is incorrect, it should look like below:
{
input: {
urn: "...place your design url here ..."
},
output:{
force: false, // true if you want to force regenerate the obj, after new model upload for ex (optional)
formats: [{
type: 'obj',
advanced: {
modelGuid: "...", // model GUID, required
objectIds: [-1] // array of dbIds to export, required. Pass [-1] to export full model, or specific dbIds ex: [49, 56, ...]
}
}],
destination: {
region: 'us' // default, optional can be ['us', 'emea']
}
}
})
You need to perform additional API call to retrieve the model GUID: see GET :urn/metadata for more details
We've been using Backbone Relational to model our ORM relationship in the front end for instance:
{
id: 2
username: "bob"
comments: [
{
id:5,
comment: "hi",
user: {
username: 'Bob'
}
}
]
}
That has been working great using models such as this in the front end:
class User extends App.RelationalModel
relations: [{
type: Backbone.HasMany,
key: 'comments',
relatedModel: 'Comment',
collectionType: 'CommentCollection'
}]
However now our api has changed and respecting more of the JSON-API Spec so the data from the back end is encapsulated inside of 'data'.
{
data: {
id: 2
username: "bob"
data: {
comments: [
{
id:5,
comment: "hi",
user: {
username: 'Bob'
}
}
]
},
meta: {
}
}
}
How can we instruct backbone relational to get the data for the 'comments' relation from .data instead of mapping the json structure directly?
For the ''class User'' we can implement the parse method like so
class User
parse: (response) ->
response.data
But how do we do this for the comments relation??
How's this?
parse: function (response) {
var fixed_response = response.data;
fixed_response.comments = fixed_response.data.comments;
delete fixed_response.json.data;
return fixed_response;
}
I'm using Sencha Architect and I'm trying to get the custom field values from this JSON response created with the Wordpress JSON API:
JSON Response
I've created a model, but I'm just not sure what to type in the "Mapping" fields for each of those custom_fields in the JSON response.
Any thoughts?
Here is my Sencha model. What do I put in the mapping areas for the last three?:
Ext.define('Ojai.model.Deal', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'Title',
mapping: 'title'
},
{
name: 'Business',
mapping: 'custom_fields.wpcf-deal-business-owner'
},
{
name: 'Expiry',
mapping: 'wpcf-deal-expiry'
},
{
name: 'Terms',
mapping: 'wpcf-deal-rules'
}
]
}
});