PHP/Python Requests to Google Webmaster Tools API - php

I'm trying to download the 'Top Queries' CSV and am having a few issues. I started off doing this via Python and I was getting GWMT to send me a CSV with all the results (and also made a script to automatically place it into an SQL database) but stopped using Python for this problem when I realized that I could not set the date range. That would be the first question (as it would make the next question irrelevant):
Does anyone know a way to query specific date ranges using Python to access the Google API? Like I said, I can download everything else but cannot set the date range (automatically gives you a month's worth).
Secondly, in term of the PHP solution, I setup XAMPP on my computer and got that working swimmingly but as soon as I started trying to download CSV's (using code from this link) but every time I load it in the Browser, no CSV is downloaded. There are few reasons why I think this might be:
API authentication not working
Something on my computer not allowing csv to be downloaded
Credentials problem in WMT
Weirdly enough, when I did the OAuth2 yesterday for Python, it worked but then when I started working this morning, the credential had been deleted? Should I just create and go through the same authentication process for Python (which gave authorization for the web property) again to allow the csv to be downloaded?
Anyways, any help on this would be greatly appreciated as the alternative is manual pulling and loading into SQL!!!! :S

The script you linked to is not supported by Google, never was, and it relies on Oauth1 which is deprecated.
Currently the only official way to download Search Queries data is via the Search Queries API, although it's in limited mode, meaning we're (Google) testing it with people who showed interest and subscribed when we announced we'll launch it in limited beta. Once testing is done, we'll very likely launch it for the general public, but I don't have a timeframe for that.
You can find the currently supported methods and more information about them in the API Explorer for Search Console (former Webmaster Tools)
For webmasters.searchanalytics.query it currently says:
[LIMITED ACCESS] Query your data with filters and parameters that you define. Returns zero or more rows grouped by the row keys that you define. You must define a date range of one or more days. When date is one of the group by values, any days without data are omitted from the result list. If you need to know which days have data, issue a broad date range query grouped by date for any metric, and see which day rows are returned.

Related

Empty MailChimp list members API response - works on API playground

Having a bit of a weird issue with a script that's previously been running for a couple of months that searches a MailChimp list for users that are subscribed but whose accounts haven't been updated in over 2 weeks (we're running nightly updates/sync on a mailing list from a database).
It was working absolutely fine up until about a week ago when I made a couple of changes. I went back and tried to put it how it was but am still getting an empty response for the query. This is the query:
/3.0/lists/{list}/members?status=subscribed&before_last_changed={-2 weeks}
I know for a fact there are around 15,000 addresses that match those query parameters, and have verified the parameters using the API playground. Searching using either the status or before_last_changed parameter works fine and returns results as expected. I've also tried changing the parameters. I also used to have count=60 in the parameters but it doesn't work with or without this (or a lower number).
I'm using the PHP MailChimp available on Github here.
Does anyone have any advice on how to troubleshoot or resolve this issue?
Edit: I'm using gmdate('c',strtotime("-2 weeks")) for the date.
It turned out to be an issue with cURL timing out. The error handling is pretty poor in that API and the timeout is set at 10 seconds. As the list is quite large and the query is quite granular, it was taking longer than 10 seconds to process.

Android - showing events nearby to user

I will take events from some websites. Then will record them to database and show the user when runs the app according to her location.
Using wamp sql database is an old and deprecated way? Like this
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
I will only record event names, location.
Should i use a database, right? I will record longitude and latitude. When user runs app, i only retrieve the events according to her locations? For example +100 - 100 meters to the location, calculating longitude latitude.
I am parsing the information from websites. I already did this in java eclipse. I used Phantomjs and jsoup. So, can i migrate them to android without changing or do you suggest anything different?
I really searched those questions but could not find such satisfying answers.
I guess there is no need to use database. You could just get the location of the device. Make a http query to your website. Parse the data by using some method and then you could show to the users.
For parsing i always use OKHTTP with jackson for parsing json data. It will be very convenient assuming your response data will be in json.
You can use jsoup in android. But not phantomjs.

Setting up an online server database and code my android native app to interact with it

Im developing a very simple native Android App containing a simple Main Menu with the Today, Yesterday, This Week, This Month and Search by Date options.
(I bought the lynda course: "Building Android and iOS Apps with Dreamweaver" with HTML5 and with the design and functionality of the app im not having too much trouble.)
What i entend with this app is this: i will write famous people profiles every day (between 1 and 5). So when people click (for example) in the Today option they will access to the profiles list that i have created for today (Yesterday and others is a check on the past written profiles from database).
So imagine that some android user clicked on today and will be presented with 3 profiles options ("Brad Pitt", "Shakira" and "Cristiano Ronaldo"), that i need the app to access my server database to update it (the "Today" profiles).
and finally...
Before the questions i want to say that i have searched on stackoverflow and found very similar answers, but im a novice on programming and when i'm reading the answers they can differ so much that i got confused going link on link documentation.
The Questions:
I want to create somekind of method that i could have a template with different profiles (Singer, Politician, Soccer Player) and click on somekind of button to start a new profile/article with Born Date, Occupation, Nationality, Biography and etc. Its this possible? How can i do it and in wich programming language?
What kind of server and what kind of database do i have to create and how to configure it to send the info to my app?
There is any server specifications that i must have for this to work the smoother and easiest possible? For this issue price is not a problem.
What kind of code should i write on my app so that it could get the "3 profiles update for today" from my website?
Its possible to show me some code example that would work with this simple step in my app of selectiong "Today" button on main menu and the app check for new profiles for today and present the user as an option? Because if i had this bit of code i could understand better how to do the rest with the profile details on the "Brad Pitt" option for example.
Hope you understood my questions. Thanks in advance. Have a nice day
Assuming that you're using the Phonegap Framework to develop your application, I would do it like so:
First of all get a Server/Webspace capable of running PHP Scripts and a MySQL Database.
You also have to rethink the way these applications work, for example you can't
configure it to send the info to my app
You need a Server Side Script (i would choose PHP for this, it's easy to learn and available on almost every Server). This PHP Script then queries your MySQL Database where all the information about the people is stored. On thing to remember is that your Clients will poll the server and request the content, you're not actively sending anything to Clients unless requested, that's just the way how HTTP works. The interface your Script is providing there is called a REST Interface.
Have a look at the link, it explains everything pretty good. Your output format should be JSON this makes it really nice to work with in the Client App later on. To do things like "what was posted today?" Have a look at how SQL Queries work and implement it in your Script.
Now for the client you can access this data by using JavaScript, most likely jQuery to simplify everything a bit. Use the jQuery $.getJSON function to access the data provided by your REST Interface. Now you can use basic jQuery to wrap this data up with HTML to present it to the user. I know that this is not "example code" or anything you requested, but it should point you into the right direction on how to achieve something like you want to do. Just do a google search for all the keywords listed above and keep reading about it, then you should be able to build a app like that.

Twitter API similar to Google Alert

I am trying to create a web application which have a similar functionality with Google Alerts. (by similar I mean, the user can provide their email address for the alert to be sent to, daily or hourly) The only limitation is that it only gives alerts to user based on a certain keyword or hashtag. I think that I have found the fundamental API needed for this web application.
https://dev.twitter.com/docs/api/1/get/search
The problem is I still don't know all the web technologies needed for this application to work properly. For example, Do I have to store all of the searched keywords in database? Do I have to keep pooling ajax request all the time in order to keep my database updated? What if the keyword the user provided is very popular right now that might have thousands of tweets just in an hour (not to mention, there might be several emails that request several trending topics)?
By the way, I am trying to build this application using PHP. So please let me know, what kind of techniques I need to learn for such web app (and some references maybe)? Any kind of help will be appreciated. Thanks in advance :)
Regards,
Felix Perdana
I guess you should store user's e-mails and search keywords (or whatever) in the database.
Then your app should make API queries (so it should be run by a server) to get some relevant data. Then you have to send data to the all users.
To understand here is the algorithm:
User adds his request to the page like http://www.google.ru/alerts
You store his e-mail and keyword in the database.
Then your server runs script (you can loop it or use cron) which makes queries to the Twitter to get some data.
Your script process all the data and send it to the user's e-mails.

PHP and Labview - grabing a value from labview and displaying the value on a webpage - two different computers on the same network

I am by no means considered a programmer. The only programming language I some what know is HTML - so be gentle :)
My boss came up to me the other day and asked me if I wanted to learn PHP, so i said sure. He threw me some text books and said here's what I want you to do:
There's a computer running labview that monitors various sensors. He wants me to take the data from the sensors and display it on a webserver on the same network. The format he wants it in: you punch in a command in a text entry box on the newly created website such as "chamber pressure" and then it takes the data that is displayed on the computer running labview and reads the value in another box that is under the first text box on the website.
Let me know where I should start. Any bit of help would be awesome.
I would start by using LabVIEW to store the data from the sensors to a database. A simple database with sensor name, value and possibly last reading time would do. MySQL databases are relatively easy to setup and work well with php I have found.
Next would be to use php on the webserver to fetch the data depending on the input and display it on the web page.
The first thing to try is the Remote Panel support built into LabView. This allows you to view or control a LabView application from a web browser on another machine. Remote Panels have many limitations (there is a restriction on max number of connected clients and the LabView runtime is required on the client) but it will only take 20 minutes to get them set up. See "Viewing an Application or Front Panel Remotely Using a Browser" in the LV help.
Remote panels are particularly good if you want to have e.g. a pull-down list of sensors and some plots that update in real time. Dynamically
updating plots are something that takes real work to implement in a web-standards way.
Use this prototype to figure out what your boss really wants to do. If his goal is to be able to peek at the chamber pressure down on the production line once in a while, you're done. If his goal is to share realtime updates on chamber pressure with 100,000 of his Facebook friends, half of whom want to view it with an iPhone or a Blackberry, then there's more work to do. Either of the approaches discussed above (using the LabView web server/web service platform, or writing everything to a database and pulling it out using php etc) will work; the latter is more scalable.
This may not be helpful, but what you've been asked to do is advanced. This should not be your first PHP project.
Start by creating a web page where you can type in a command code and a hard-coded value will be displayed based on what code was typed in.
If you know how to access a Webservice from within PHP, you could build your LabVIEW app as a webservice and access that from PHP. But without any proper training (LabVIEW and PHP) that will take you quite some time.
Ton

Categories