Where to get product-catalog-id - facebook-graph-api

I am using Facebook marketing API 3.3 version to read product feeds but I don't know where can I get the product-catalog-id.Here is the URL :
GET /v3.3/{product-catalog-id}/product_feeds

You can get your product-catalog-id in the settings page of catalog page (https://www.facebook.com/products/catalogs)

Programatically, I'm using Graph API 13.0, you can fetch your business id via:
GET me/businesses
response:
{ data: [ { id: 12345, ... }, { id: 23456, ... } ] }
Then use the business ID to fetch product catalogs:
GET ${businessId}/owned_product_catalogs
response:
{ data: [ { id: 12345, name: 'foo', ... }, { id: 23456, name: 'bar', ... } ] }
See https://developers.facebook.com/docs/marketing-api/reference/product-catalog

Related

Power BI embed with React Js

This is the first time I am trying to embed a Power BI report with React.
I used the following method and it is working fine. But the issue is that my access token failed after nearly one hour. When I run the project after one hour I have to generate a new access code and add it into the following code. What is the solution for this ?
my code -->
<PowerBIEmbed
embedConfig={{
type: 'report',
id: 'xxxxx',
embedUrl: "xxxxx",
accessToken: ' xxxxxxxxx',
tokenType: models.TokenType.Aad,
settings: {
panes: {
filters: {
expanded: false,
visible: false
}
},
background: models.BackgroundType.Transparent,
}
}}
eventHandlers={
new Map([
['loaded', function () { console.log('Report loaded'); }],
['rendered', function () { console.log('Report rendered'); }],
['error', function (event) { console.log(event.detail); }]
])
}
cssClassName={"Embed-container"}
getEmbeddedComponent={(embeddedReport) => {
window.report = embeddedReport;
}}
/>
Thank you
Jeewan
You have to purchase a premium licence.
https://learn.microsoft.com/en-us/power-bi/enterprise/service-premium-features

Facebook graph: error in after cursor

when I make a get request on facebook graph api, for page search, everything is fine. But when I use the after cursor or click on the 'next' field I get the following error:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "B4oyy5hYamh"
}
}
until yesterday everything worked perfectly, but today I found this problem.
this is my first request:
https://graph.facebook.com/v2.10/search?access_token=*******&fields=about,paging&type=place&center=41.817557,12.446137&categories=["FOOD_BEVERAGE"]&distance=2000&limit=25
and this is the request for the next page:
https://graph.facebook.com/v2.10/search?access_token=*******&fields=about,paging&type=place&center=41.817557,12.446137&categories=["FOOD_BEVERAGE"]&distance=2000&limit=25&after=QWJwc3kyZAklVTVpZAMmlEd0hFdXRINWVOU2hPSDQ5SWtYcXFreHFGX2pTVndHMW9DOV9BTmgtVGlxN04xUDJheXRCSGZAabjZAxUVJnbE5wRmcyMU4yQ3J3ZAkRqVVE1NHpjQWhPZAkh5clA1MnUxNV9WTzU1TngzYlhfVkRfZAGs2SWZAkNXNFQ3RQWEd2Rk1hNXdGRW5vdmlNbFh3aDl4YzlSdmxWUkQ4RzFGTnFZAbUxqYzhnMFZASYkxuWHJobUttSkdwZAWZANUnkwN1AyQm93Tnh1bnYwT0ZAEMVRyYXhZAMldFNF9SNjlCMGttWmZA6SGdKSUN4aXZAyLVZAmOUJ4RnM3SFJRNHNUY3lUNDUyOGo2VTdrWUJYcDh3SVd2dDdOWlBzZAUhPZA0tzY0czM25hU25iNmI0ZATN0UFFQZAGlJSFdEd2J3bVUycUZAvNE5YVEw4QlJmTUJmNlpvUWd0Y1pQOE9aWnpKOFlkZAFIxcTU2UXBJTzRR
Your after seems incorrect, it should be a very short code. Have you pasted an access token instead?
This query
https://graph.facebook.com/search?q=food&type=page&limit=3&access_token=ACCESS_TOKEN returns
{
data: [
{
name: "Food Network",
id: "20534666726"
},
{
name: "FOODbible",
id: "996909263665350"
},
{
name: "Food",
id: "113109208703114"
}
],
paging: {
cursors: {
before: "MAZDZD",
after: "MgZDZD"
},
next: "https://graph.facebook.com/v2.5/search?access_token=ACCESSTOKEN&pretty=1&q=food&type=page&limit=3&after=MgZDZD"
}
}
so to fetch the next list, I simply append the after value (MgZDZD) to my initial query to fetch the next page of results. eg
https://graph.facebook.com/search?q=food&type=page&limit=3&access_token=ACCESS_TOKEN&after=MgZDZD

Ember model relationship not matching API

I have two models who look like this:
// models/database.js
export default DS.Model.extend({
title: DS.attr(),
/*...*/
documents: DS.hasMany('document')
});
// models/document.js
export default DS.model.extend({
name: DS.attr(),
/*...*/
database: DS.belongsTo('database')
});
Is also have some routes
Router.map(function() {
this.route('databases', function() {
this.route('database', { path: ":database_id" }, function() {
this.route('documents');
});
});
});
When I call /database/[ID]/documents if got nothing.
I think the problem is I'm working with an JSON HAL API and when I ask for databases on API I receive this kind of response.
{
"_embedded": {
"databases": [
{
"_links": {
"self": {
"href": "<API_URL>/databases/7ec39267b544424c/",
"reference": "7ec39267b544424c",
"title": "00000006"
}
},
"database": {
"name": "00000006",
"reference": "7ec39267b544424c",
"title": "****"
}
},
{
"_links": {
"self": {
"href": "<API_URL>/databases/aace19af004144a4/",
"reference": "aace19af004144a4",
"title": "00000007"
}
},
"database": {
"name": "00000007",
"reference": "aace19af004144a4",
"title": "******"
}
}
}]
}
As you can see there no documents attributes on JSON returned.
If I want a database's documents I've got to call [API_URL]/databases/[ID]/domains/[ID]/documents
There's still a way to link documents to a database by specifying that the documents are recoverable at this URL (/databases/[ID]/domains/[ID]/Documents)?
I found the solution.
I've override extractRelationships method in hal serializer like this:
extractRelationships(modelClass, resourceHash, included) {
resourceHash._links["documents"] = {
"href" : "/databases/" + resourceHash.id + "/domains/" + (resourceHash.name || resourceHash[modelClass.modelName].name) + "/documents/"
};
return this._super(modelClass, resourceHash, included);
}
I just add a link to documents for each databases returned by the API.
I've modified my route for documents like this
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model() {
return this.modelFor('databases.database').get('documents');
}
});
And now it works perfectly.
I think what you're looking for is a HAL API to JSON API converter. To avoid doing this yourself manually I'd recommend the http://github.com/201-created/ember-data-hal-9000 Ember plugin, which I've used myself to get Ember Data to play nice with Spring Boot.
If you wanted to see a simple example here's my client-side and server-side demo app.
Additionally, if you were curious what Ember, and JSON API don't use HAL you can read here JSON API - FAQ on HAL.

Ember save() throws JSON.parse error: "unexpected end of data at line 1 column 1 of the JSON data"

I have a model record created and being saved through a route and controller. When I save the record through the controller (via a savePlace action), I am seeing this error in the JS console:
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
I've tried not setting anything on the model as well as setting dummy data on the model, but I get the same error. I am also user ember-cli http-mocks as a test backend to handle JSON responses. I realize it may be the response, but I'm not sure how else to configure the response.
Here's the relevant code:
routes/places/new.js:
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.createRecord('place');
},
});
controllers/places/new.js:
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
saveGeom(geom) {
this.get('model').set('geometry', geom);
},
savePlace(data) {
this.get('model').set('name', this.get('name')).set('description', this.get('description'));
this.get('model').save().then(function() {
alert("SUCCESS");
}, function(error) {
console.log(error);
});
}
}
});
server/mocks/place.js:
placeRouter.post('/places', function(req, res) {
res.setHeader('Access-Control-Allow-Methods', 'POST');
res.send({
"places": {
id: 1,
name: "Triangle",
description: "Ryan Christiani",
geometry: {
"type": "Polygon",
"coordinates": [
[
[-84.32281494140625,34.9895035675793],
[-81.73690795898438,36.41354670392876],
[-83.616943359375, 34.99850370014629],
[-84.05639648437499,34.985003130171066],
[-84.22119140625, 34.985003130171066],
[-84.32281494140625,34.9895035675793]
]
]
}
}
});
});
Thanks!
I think you are using the wrong brackets in the wrong places in your JSON Object.
Check out this page
http://www.tutorialspoint.com/json/json_syntax.htm
The http-mocks configuration is wrong. It should be this the code snippet below. The server was instead responded with an array of objects (the response for 'GET /'). Not sure why that would trigger a JSON.parse error, but this is the correct configuration.
placeRouter.post('/', function(req, res) {
res.setHeader('Access-Control-Allow-Methods', 'POST');
res.send({
'places': [
{
id: 1,
name: "Using Ember CLI to create a Fixture Adapter.",
description: "Ryan Christiani",
geometry: {
"type": "Polygon",
"coordinates": [
[
[-84.32281494140625,34.9895035675793],
[-81.73690795898438,36.41354670392876],
[-83.616943359375, 34.99850370014629],
[-84.05639648437499,34.985003130171066],
[-84.22119140625, 34.985003130171066],
[-84.32281494140625,34.9895035675793]
]
]
}
}]});
});

Traversing a complex RESTful output (version 12)

I'm getting following (simplified) output from a RESTful API:
{products: [{
product: {
id: 1, name: "T-Shirt red"
},
images: [{
id: 1, size: 'm', url: 'http://db.co/t-shirt-red_m.jpg'
}, {
id: 2, size: 'xl', url: 'http://db.co/t-shirt-red_xl.jpg'
}]
}, {
product: {
id: 2, name: "T-Shirt blue"
},
images: [{
id: 3, size: 'm', url: 'http://db.co/t-shirt-blue_m.jpg'
}, {
id: 4, size: 'xl', url: 'http://db.co/t-shirt-blue_xl.jpg'
}]
}]}
Using Ember version 12, how should the declaration of the Product model looks like and how can I traverse the results? Haven't been able to find any example in that direction.
Following to access the data doesn't work (I just can't find the right syntax):
var products = App.Product.find(); // seems to work
var prodNames = products.getEach('product.name'); // doesn't work
var secondProd = products.getObject(1).get('name'); // doesn't work
Thanks a lot in advance!
claudio.
DS.hasMany and some options for the REST adapter may help you.
I've used a similar setup with MongoDB embedded models. I've attached some examples below.
I didn't want to try to save to the embedded array, so I've used embedded:load, but you can use embedded: 'always' to persist the total object back to the server (although it didn't work quite as I expected) with 'always' if you save the parent object.
DS.RESTAdapter.map 'App.Check',
line_items: { embedded: 'load' }
parties: { embedded: 'load' }
App.Check = DS.Model.extend
description: DS.attr("string")
modified_date: DS.attr("date")
parties: DS.hasMany('App.Party')
App.Party = DS.Model.extend
name: DS.attr("string")
check: DS.belongsTo('App.Party')
You can then reference the item. In a view, I've accessed it as below from a ArrayController where the content is set to an instance of DS.Check.
{{#each party in content.parties }}