How to send BatchRequest? - php

It's been first time when I am going to use an APi for working with a Web Application. Google Analytics Dev-Guides show a Basic sample which is shown below.
I am TOTALLY UNAWARE of how to execute it..Okay, I would replace ViewId with mine.. Do I have to save it in .php Format ? or what ? anybody here can tell me step by step procedure
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests":
[
{
"viewId": "XXXX",
"dateRanges": [{"startDate": "2014-11-01", "endDate": "2014-11-30"}],
"metrics": [{"expression": "ga:users"}]
}
]
}

Go though the steps in the Hello Analytics API for JavaScript
create a google developer project
get your API credentials and a View ID you own.
load the webpage.
If you get stuck on a particular step come back and ask for help.

Related

need to some action on the api response codeigniter

Hello I have build application using codeigniter,
where i create one folder inside controllers like api.
it has few files like api/controller.php, api/user.php
i echo json from the all api controllers.
now i have to do some change with the json which is pass to api from one place.
it is not feasible to got to every controller and each function to so this change.
is there is any way like from any core file or anything where i can do code and it will be proceed before the api receive the output.
rg.
Get Attendee API :
current response : {success:true,attendeeList:{list of attendees}}
now i have to change every reponse like
{succss:true,data:{success:true,attendeeList:{list of attendees}} }
Hello I Have solved this by using $hook['display_override'];
enter image description here

after login dynamic menu API getting CORS error

I am using Angular 6 and codeigniter project.in the project I am using slider and nav menu-bar are dynamically fetching through REST API. Normally its working perfectly after Login its occurring the CORS error
after login its getting like this
please help me to solve this.
CHOICE 1
Create a proxy.conf.json file in your angular and add following code
{
"/api": {
"target": "http://localhost:3000", //Your Targeted server host
"secure": false
}
}
Go to angular.json and add following code under serve command
"proxyConfig": "proxy.conf.json"
Code looks like
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "sample:build",
"proxyConfig": "proxy.conf.json"
}
CHOICE 2
Simply go to chrome store and download the extenstion called Allow-Control-Allow-Origin: * , turn it ON. Magic Happens.

Refresh Website with Python Post Information OR open other link in existing tab with Python

I'm a bit lost at the moment and I hope that you can help!
I try to recognize people with OpenCV in Python. This is working so far. With the id of the recognized person I want to display information which belong to her or him.
For that I tried something like this:
1)
import webbrowser
webbrowser.open('http://mysite/index.php?userID=XYZ', new = 0)
But although I wrote the "new = 0" it opens a new browser tab everytime an other userID stands in the link.
2) An other approach was to send information via a http post request to the website like:
url = 'http://mysite/index.php'
query = {'personID': XYZ}
res = requests.post(url, data=query)
But doing this I don't have any idea how to work with this post command in my PHP code so it refreshes the site with the data belonging to user XYZ..
May you help me please?
Kind regards
Edit1 - START:
A small php example with using GET parameters would be something like this
<?php
echo("<html><head><title></title></head><body>");
if ($_GET['userID'] == 1) {
echo("<div id='userContent'>Hello User 1</div>");
}
else if ($_GET['userID'] == 2) {
echo("<div id='userContent'>Hello User 2</div>");
}
else {
echo("<div id='userContent'>Public, non user specific information</div>");
}
echo("</body></html>");
?>
But at this point I don't know how to make this site to a dynamic one which shows different information when Python sends a request..
Edit1 - END
This is not possible in webdriver currently. The 0 flag refers to the window, not the tab. See a discussion of this on reddit here. Another question also asked this on Stack Overflow but got no answers.
It is possible however with the much more feature rich package Selenium.
import time
from selenium import webdriver
link1="http://mysite/index.php?userID=ABC"
link2="http://mysite/index.php?userID=XYZ"
driver=webdriver.Firefox()
driver.get(link1)
time.sleep(5)
driver.get(link2)
Selenium does require some installation steps: http://selenium-python.readthedocs.io/installation.html
Regarding using requests, there's no reason you can't do a GET request so you don't have to worry about handling a post request:
import requests
url = "http://mysite/index.php?userID=ABC"
res = requests.get(url)
print(res.text)
Without seeing more of your php code or knowing more details, it is hard to say what approach is best for you but this should get you past the issues you mentioned.

No result from google API PHP

I want to get the distance from one point to another using the google API, but I'm having some issues.
My API link is:
http://maps.googleapis.com/maps/api/directions/json?origin=55.061744,9.429565&destination=Opnæsgård,%20Hørsholm,%20Denmark&alternatives=true&sensor=false
If I access this link from the browser, I get the correct distance however; when I try to access the exact same URL from my php script, I get an error.
My php script:
<?php
print_r(file_get_contents('http://maps.googleapis.com/maps/api/directions/json?origin=55.061744,9.429565&destination=Opnæsgård,%20Hørsholm,%20Denmark&alternatives=true&sensor=false'));
?>
Output from php script:
{ "routes" : [], "status" : "NOT_FOUND" }
As you can see, I'm getting two different results with the same URL, and I have no idea why.
I have also tried using CURL in the php script without any luck.
I hope you can help me
//Mikkel

angular js with php integration

I used the code from http://angularjs.org/ (Wire up a Backend)
Here in project.js
angular.module('project', ['firebase']).
value('fbURL', 'https://angularjs-projects.firebaseio.com/').
factory('Projects', function(angularFireCollection, fbURL) {
return angularFireCollection(fbURL);
}).
config(function($routeProvider) {
I used this code in my web page. Instead of https://angularjs-projects.firebaseio.com/ url i want to use my url i.e http://test.com/test.php. But it didn't work.
Also i want to know in my php file in which format the out put should be?
Do you need to echo the content in php file or use the return command? Please give suggestion. I have searched a lot. I couldn't find the solution.
I think in firebase url https://angularjs-projects.firebaseio.com/ they are returning the response from their back-end service. That is why it didn't worked for you even if you changed the URL.
And answer to your second question;
If you make a call to your back-end service its better to have a json response style from your PHP and you don't have to use any return command for that. Instead you should echo your contents.
For example in your PHP file if you are getting the results as an array you can give back the response to the angular application as;
echo json_encode($result_array);
Hope it helps.
I think you should separate backend and frontend and treat them as two separated application. Both apps should communicate with each other by sending ajax request (front) and respone data in json format (backend). In my opinion it's the best way to handle this.

Categories