Issue with Product.search API call - javascript

I'm using Big Cartel's Dugway development environment, and trying to build a live search with Product.search (available with their JS API). It appears to return a set of 20 products no matter what search term, or limit I place on the call, and I'm wondering if anybody else has experienced this? Is it just an issue with the Dugway environment?
More specifically, this is the call I'm making:
Product.search('mugs', { limit: 5 }, function(data) {
console.log(data);
});

This is just the way that products.js works with Dugway, I can confirm that the limit works properly in a live Big Cartel shop. For now maybe you just want to create a for loop and stop at 5 results, or only retrieve 5 from the response another way.

Related

Fetching data from multiples pages of API

I'm fetching data from a PS4 Games API but it's split into 400+ pages. I wanted to get the data from all pages, but the solution I came up with did not work very well. It gives me an error 'JSON Value of type NSNull cannot be converted to a valid URL'. Also, I don't think the for loop works well either, it shows me it going through all the pages when it displays the results in my list.
Additionally, this API is dynamic because new games keep getting released. So how could I get data up to latest page without manually changing my last page number everytime? I looked at some questions here but I couldn't fit it into my code
My code is rather long so I'm just going to post the part that matter:
componentDidMount() {
var i;
for (i = 0; i < 400; i++) {
fetch(`https://api.rawg.io/api/games?page=${i+1}&platforms=18`, {
"method": "GET",
"headers": {
"x-rapidapi-host": "rawg-video-games-database.p.rapidapi.com",
"x-rapidapi-key": "495a18eab9msh50938d62f12fc40p1a3b83jsnac8ffeb4469f"
}
})
.then(res => res.json())
.then(json => {
const { results: games } = json;
this.setState({ games });
//setting the data in the games state
});
}
}
The API also has an item that gives me the link of the next page, I think there is a way to use 'next' and fetch data from that URL
If anyone could help, that would be AWESOME. Thank you in advance
its my first answer on this forum, so... I hope be helpfull.
For me you have 2 options:
Each request send 2 variables in the answer count and next, or you make a for loop with count/20 as limit (20 is the number of items gaves in the answer), or you make a while loop until the next variable give null as answer (currently at page 249).
What is currently happening is you are making 400 requests and when each comes in it is overwriting the component with the response it received. It does not care about what is already there or any of the other requests.
An approach you could try instead is as the responses come in append the results to the ongoing list and update the state with the running list.
Going forward and for your other question about handling new releases. Instead of running 400 queries every time the application is used, try looking into caching the results. When the app loads you can see if cache exists and load or query if it does not. The rawg.io /games endpoint has a parameter for ordering by release. When the application loads in future you can conditionally loop until you reach a game that is already in cache at which point terminate.

Elegant way of harnessing facebook ads data without api

I was helping one of my relatives with a Facebook campaign for their store.The campaign was a success as we gathered about more than 1000 new likes and a lot of queries.They were happy but I really wanted to do some more with that data like tag those people who liked if their setting allowed or send a message on messenger for arrival of new items.In short keep a track of the all that was happening.The idea is to harness the data so that maximum can be achieved next time on similar campaigns.
I wanted a something simple so that the guys at the store can do it themselves without any fiddling with api.After some trial and error i came up with this js code which can be pasted into console after opening the window which appears when you click link just on the side of like button.
/*a script to get all the people who liked the page
after a facebook campaign. A successful capmpaign will get 1000's of
likes so it will be impossible to load all the names in one go.Also the
list loads progressively with each scroll. So
the code introduces a last element in the json which you have to put in
place of "i" in the given code when you press see more button in
subsequent runs.On my fairly powerful laptop and decent internet I was
not able to get more than 350 persons without a good lag.
The value of i is calculated by trial and error as the data attributes `
before that holds something else(not required) and not the names.I hope
it will be more or less similar in all of them.
This code is to be pasted in the console once the window with all the
likes is opened.*/
var arrayName = document.querySelectorAll('[data-gt]');
var PersonObject={};
try {
for(var i = 55;i<=arrayName.length;i++ ){
var element=arrayName[i];
console.log(element);
var name=element.innerHTML;
// console.log(i)
PersonObject[("name"+i)]=name;
// console.log(PersonObject)
}
}
catch(error){
console.log("error occured at"+i)
}
finally{
PersonObject["lastElement"]=i;
var NamesJson = JSON.stringify(PersonObject)
console.log(NamesJson)
}
I tried to write the gist of code in comments.
Now my real question,this all seems so hacky and patched stuff but not elegant. Isn't there a way for business owners to actually harness this data in more systematic way without the need for any api's or any programming knowledge?

Parse.com Javascript SDK using include, but not working

I'm trying to fetch data from a table called Book. Inside Book there's a Pointer<ParseUser> which holds the pointer of one user. The ParseUser has another pointer called Pais (which means Country in spanish). So I want to fetch every single info from any Book:
var query = new Parse.Query("Book");
query.include("user");
query.include("user.pais");
query.find({
success: function(books) {
response.success(books);
},
error: function(error) {
response.error({'resp': error.code, 'message': error.message});
}
});
and I don't get the objects, just the pointers:
Why ? I know it works ok when I call it in iOS or Android with include(String key) or includeKey: NSString* key.
Why doesn't it work with Javascript??
Thank you in advance.
Regards.
Rafael.
EDIT:
Oh and I just forgot... I've tried with:
query.include(["user"]);
and
query.include(["user", "user.pais"]);
I've seen some examples where developers used it.
SECOND EDIT:
The last thing I've used is fetch like:
Parse.Object.fetchAll(books, {
success: function(list) {
response.success(list);
},
error: function(error2) {
response.error({'resp': error2.code, 'message': error2.message});
},
});
But didn't work either.
This is starting to freak me out.
OUR WORKAROUND:
The workaround we're trying to do is fetching everything separately, and then returning back to the user together. This is not a good practice since a little change in the class in a future would ruin the whole function.
Is this a bug in the SDK ?
(This is a comment turned into an answer)
Just a thought because I recently had a problem with CloudCode that is quite similar to yours. What version of the JavaScript SDK are you using? I solved my problem by changing the version back to 1.4.2. It's just a shot in the dark in your case, but it might work.
Here is the thread where I described the problem and how to solve it by changing the SDK version.

parse cloud code job : delete rows that have been in DB for an hour

I'm using parse as a mobile backend for an ios app I'm developing. I know its probably not a permanent solution but for what I'm doing right now it gives me good test results. I need to create a cloud code job which will remove all the rows with entries older than one hour in all of my databases besides one (this DB is just for the sake of having a backup of everything).I want to do this so client side devices can only query for things in the DB that are less than an hour old. I have a "timestamp" on each entry which I was going to incorporate into a js function to first check If all the entries were indeed an hour or more old, and if they were, delete them. I've been doing some research and really havent been able to develop a js function that would do this (I have absolutely no js experience whatSoEver just obj c) from my understanding it would be something similar to this
Parse.Cloud.job("deleteRows", function(request, status) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query(//inverse of db i dont want to delete from);
query.each(function(//row in db?) {
// delete here under parameters ?
}).then(function() {
status.success("rows deleted");
}, function(error) {
status.error("job incomplete");
});
});
if anyone could give me a hand I'd really appreciate it. Thanks.
Why do you want to delete all entries? You can do a query to collect data within 1 hour old. I am not familiar with iOS development but this could help you with a hint:
https://www.parse.com/questions/query-for-objects-created-in-the-past-20-minutes-and-the-opposite

JavaScript OAuth sign in with Twitter

I have to integrate Sign-in-with Twitter in my app as below.
https://dev.twitter.com/docs/auth/sign-twitter
It is browser based app developed in JavaScript
I have been refering google code java script OAuth, but im confused how to use oauth/authenticate and how to get the oauth_token
Can any one please help me out with some samples ?
Problem with this is that anyone who views your page can also now view your consumer key and secret which must be kept private.
Now, someone could write an app that uses your app credentials and do naughty and bad things to the point that twitter and users ban you, and there isnt anything you can do.
Twitter do state that every possible effort must be made to keep these values private to avoid this happening
Unfortunately, there is currently no way to use oAuth in Browser based JavaScript securely.
Check out the Twitter #Anywhere JSDK authComplete and signOut events and callbacks at https://dev.twitter.com/docs/anywhere/welcome#login-signup
twttr.anywhere(function (T) {
T.bind("authComplete", function (e, user) {
// triggered when auth completed successfully
});
T.bind("signOut", function (e) {
// triggered when user logs out
});
});
Use below code in consumer.js and select example provider in index.html drop down list
consumer.example =
{ consumerKey : "your_app_key"
, consumerSecret: "your_app_secret"
, serviceProvider:
{ signatureMethod : "HMAC-SHA1"
, requestTokenURL : "https://twitter.com/oauth/request_token"
, userAuthorizationURL: "https://twitter.com/oauth/authorize"
, accessTokenURL : "https://twitter.com/oauth/access_token"
, echoURL : "http://localhost/oauth-provider/echo"
}
};
Since I was searching for the same thing, trying not to use a custom PHP solution, I came across this very simple integration at http://www.fullondesign.co.uk/coding/2516-how-use-twitter-oauth-1-1-javascriptjquery.htm which uses a PHP proxy that accepts whatever twitter api call you'd like to retrieve from your javascript ..
I'm definitely taking a look at it

Categories