Echo avatars of project members Basecamp (PHP) - php

I'm working on a Basecamp widget which will have to show important information about the projects we are currently working on. Since I could not find any relevant and detailed documentation on this matter I would like to ask the community for help.
My Situation
I'm currently already echo-ing my projects, this data contains:
Project Name
Description
Project ID
And for my To-Do Items I echo the following data:
Remaining To-Do Items
Completed To-Do Items
Total To-Do Items
Progression in percentages
My goal
I'd like to show the avatars of all the people working on each individual project. Since this kind of programming is fairly new to me I'd appreciate some guidance on this matter.
Since Basecamp is becoming more popular I think more people could be interested in this information. I have consulted the API for Basecamp and written a small part to attempt the echo-ing of the project members but in vain.
I thank you for your help in advance.
Cheers,
J.I.N.
(Post scriptum: This is the complete source I have until now, some value's are deliberately altered to cloak data like credentials etc. Sorry for the long post, I tried to keep it as brief as possible)
Authentication & Retrieving Project Data
$appName = 'MyAppName';
$appContact = 'MyAddress';
$basecampAccountId = 'MyAccountID';
$basecampUsername = 'MyBaseCampUsername';
$basecampPassword = 'MyPassword';
$baseUrl = "https://basecamp.com/************/api/v1";
$url= $baseUrl.'/projects.json';
$credentials = "$basecampUsername:$basecampPassword";
$helloHeader = "User-Agent: $appName ($appContact)";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //optional
curl_setopt($ch, CURLOPT_MAXREDIRS, 3); //optional
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); //optional
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //optional
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); //optional
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($helloHeader));
$response = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
curl_close($ch);
Retrieving To-Do Lists
$json = $response;
$data = json_decode($json);
/*echo "<br/><br/>";*/
foreach($data as $key)
{
echo "<ul>";
echo "<li>".$key->name."</li>";
echo "<li>".$key->id."</li>";
echo "<li>".$key->description."</li>";
$url= $baseUrl.'/projects/'.$key->id.'/todolists.json';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
// curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //optional
curl_setopt($ch, CURLOPT_MAXREDIRS, 3); //optional
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); //optional
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //optional
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); //optional
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($helloHeader));
$response = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
curl_close($ch);
// print_r($response);
$json = $response;
$data = json_decode($json);
$todo_remain = $data[0]->remaining_count;
$todo_completed = $data[0]->completed_count;
$todo_total = $todo_remain + $todo_completed;
echo "<BR>";
echo "<BR>";
echo "Remaining To-Do Items:";
echo "<BR>";
echo $todo_remain;
echo "<BR>";
echo "Completed To-Do Items:";
echo "<BR>";
echo $todo_completed;
echo "<BR>";
echo "Total To-Do Items:";
echo "<BR>";
echo $todo_total;
echo "<BR>";
echo "Remaining percentage is: <BR>";
echo round(($todo_remain/$todo_total)*100);
echo "%";
echo "<BR>";
echo "Completed percentage is: <BR>";
echo round(($todo_completed/$todo_total)*100);
echo "%";
echo "</ul>";

Related

Get access token to Flipkart seller account using php

Can anyone help to get access token by using Flipkart app id and app secret.
We have tried with the code below:
<?php
$username='appid';
$password='appsecret';
$url='https://api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$output = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$info = curl_getinfo($ch);
curl_close($ch);
if(curl_errno($ch)){
echo 'Curl error: ' . curl_error($ch);
}
print_r($output);
echo $status_code;
But we get the error:
{"error":"invalid_grant","error_description":"Unauthorized grant type: client_credentials"} 400
I ran through the same issue and after struggling for a couple of hours I went to my seller account and recreated my "Application Id" and "Application Secret". The only difference I made was I selected "self_access_application" instead of "third_party_application" this time and I was good to go.
Please refer: https://nimb.ws/sziWmA
Hope this helps
Thanks
You can try this code, i also faced the same issue.
$url = "https://api.flipkart.net/oauth-service/oauth/token?grant_type=client_credentials&scope=Seller_Api";
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, config('constants.flipkart.application_id').":".config('constants.flipkart.secret_key'));
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
$token = json_decode($result,true);
if(isset($token['access_token'])){
$this->access_token = $token['access_token'];
}
you can try this it will be helpful python/odoo developer
def flipkart_token_generation(self):
if not self.flipkart_sandbox_app_id or not self.flipkart_sandbox_cert_id:
raise UserError(_("Flipkart: cannot fetch OAuth token without credentials."))
else:
url = "https://sandbox-api.flipkart.net/oauth-service/oauth/token"
data = {'grant_type': 'client_credentials', 'scope': 'Seller_Api'}
response_json = requests.get(url, params=data, auth=(self.flipkart_sandbox_app_id, self.flipkart_sandbox_cert_id)).json()
self.env['ir.config_parameter'].sudo().set_param('flipkart_sandbox_token', response_json["access_token"])

Trying to access both a json from google places api and then access the photo reference returned by this json

I'm currently working with the google places api to display a list of restaurants near a users location. The json returns the names of the restaurants along with details and a string that represents a photo reference. In order to actually get the picture itself you need to put the reference string in google's place photos api, as detailed here. I thought I coded everything correctly but the json I'm getting from the place photos api is null and I can't figure out why.
define("PLACES_API_ENDPOINT", "https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaraunts+near".$address);
$curl1 = curl_init();
curl_setopt($curl1, CURLOPT_URL, PLACES_API_ENDPOINT . "&key=my key");
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl1, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl1);
/*echo "<hr>";*/
//var_dump($response);
$response = json_decode($response, true);
echo "<hr>";
var_dump($response);
echo "<hr>";
var_dump($response["results"][0]["photos"][0]["photo_reference"]);
$photoReference=$response["results"][0]["photos"][0]["photo_reference"];
define("PHOTOS_API_ENDPOINT", "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=".$photoReference);
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, PHOTOS_API_ENDPOINT . "&key=my key");
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
$responsePhoto = curl_exec($curl2);
/*echo "<hr>";*/
//var_dump($response);
$responsePhoto = json_decode($responsePhoto, true);
echo "<hr>";
var_dump($responsePhoto);
echo "<hr>";

Walmart API Search Products

I am trying to get search products for a keyword
My code:
$searchquery = "ipod";
$api_endpoint = "http://api.walmartlabs.com/v1/search";
$postfields = "apiKey=". $appid ."&query=" . $searchquery;
//$postfields = array('apiKey' => $appid, 'query' => $searchquery);
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $api_endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
//curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, true);
curl_setopt($connection, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($connection, CURLOPT_HEADER, true);
//curl_setopt($connection, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($connection);
curl_close($connection);
print_r($api_endpoint);
print_r($response);
When i go in browser and visit api.walmartlabs.com/v1/search?apiKey={appid}&query=ipod , it shows results, but when i try to do with curl , it shows
"Action Not Found"
Here is the Screenshot
Any help would be appreciated.
looking on the doc (https://developer.walmartlabs.com/io-docs) it appears that the server expects a GET request.
Just replace your POST request with a GET request and all should be fine
$searchquery = "ipod";
$api_endpoint = "http://api.walmartlabs.com/v1/search";
$urlParams = "apiKey=". $appid ."&query=" . $searchquery;
$fullUrl = $api_endpoint . '?' . $urlParams;
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $fullUrl);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($connection, CURLOPT_HEADER, true);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($connection);
curl_close($connection);
print_r($api_endpoint);
print_r($response);
<?php
ini_set('display_errors', 1);
//API URL : https://affiliates.walmart.com/#!/api
$api_key="**********"; //https://developer.walmartlabs.com/apps/mykeys
$keywords="men%20watches"; // Search text - whitespace separated sequence of keywords to search for
$format="json"; // data we want in response
$responseGroup="base"; // Specifies the item fields returned in the response, allowed response groups are [base, full]. Default value is base.
$sort='price'; //Sorting criteria, allowed sort types are [relevance, price, title, bestseller, customerRating, new]. Default sort is by relevance.
$order="asc"; //Sort ordering criteria, allowed values are [asc, desc]. This parameter is needed only for the sort types [price, title, customerRating].
//http://api.walmartlabs.com/v1/search?apiKey={apiKey}&lsPublisherId={Your LinkShare Publisher Id}&query=ipod
$request_url="http://api.walmartlabs.com/v1/search?apiKey=".$api_key."&query=".$keywords."&format=".$format."&responseGroup=".$responseGroup."&sort=".$sort."&order=".$order;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$request_url);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
// Check for errors and display the error message
if($errno = curl_errno($ch)) {
$error_message = curl_strerror($errno);
echo "cURL error ({$errno}):\n {$error_message}";
}
curl_close($ch);
$arr = json_decode($retValue,true);
echo "<pre>";
print_r($arr);
// echo "<pre>";
// var_dump($retValue);
?>

Fetching xml with curl on https

So I made a login to site like this:
$ch = curl_init('https://emea2cps.adobeconnect.com/api/xml?action=login&login=username&password=password');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_exec($ch);
$info= curl_getinfo($ch);
echo 'passed' . $info['total_time'] . ' secconds ' . $info['url'] . '------ and http-code'. $info['http_code'];
print curl_error($ch);
After I want to fetch XML of my meetings by this link https://meet77842937.adobeconnect.com/api/xml?action=report-my-meetings
I tried the following code:
$ch1 = curl_init('https://meet77842937.adobeconnect.com/api/xml?action=report-my-meetings');
curl_setopt($ch1,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch1, CURLOPT_SSLVERSION,3);
curl_setopt($ch1,CURLOPT_RETURNTRANSFER,TRUE);
$data = curl_exec($ch1);
$info1= curl_getinfo($ch1);
echo 'passed' . $info1['total_time'] . ' secconds ' . $info1['url'] . '------ and http-code'. $info1['http_code'];
print curl_error($ch1);
curl_close($ch1);
curl_close($ch);
$xml = new SimpleXMLElement($data);
print_r($xml);
What can you advise me?
Note: i can see xml when i input this link on browser
Structure:
<results>
<status code="ok"></status>
<my-meetings>
<meeting sco-id="1282590819" type="meeting" icon="meeting" permission-id="host" active-participants="0">
<meeting sco-id="1282620938" type="meeting" icon="meeting" permission-id="host" active-participants="0">
</my-meetings>
</results>
Output:
like this for ex:
sample1aksamaimeet77842937.adobeconnect.com/sample1/2014-02-28T06:15:00.000-08:002014-02-28T07:15:00.000-08:00false01:00:00.000sample2meet77842937.adobeconnect.com/sample2/2014-02-28T06:15:00.000-08:002014-02-28T07:15:00.000-08:00false01:00:00.000
Try adding this:
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, FALSE);
Also:
$data = curl_exec($ch1); // after this line
var_dump(htmlentities($data)); // add this one
to see what's the output. It'll give you a starting point to debug.
UPDATE
Add:
curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__.'/cookies');
curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__.'/cookies');
// repeat this for all $ch, $ch1, $ch2 and such where you need auth cookie available
to store the login information and reuse it in other requests. Your error shows your second request goes unauthenticated. So I assume first one sets a cookie for login unless you need to carry over a variable returned by the first login sequence.
AND remove the \ in password\. Your password has an extra character that should not be there!
Working code:
// Login.
$ch = curl_init('https://emea2cps.adobeconnect.com/api/xml?action=login&login=username&password=password');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEFILE, __DIR__.'/cookies');
curl_setopt($ch,CURLOPT_COOKIEJAR, __DIR__.'/cookies');
$data = curl_exec($ch);
var_dump($data);
curl_close($ch);
// Query.
$ch = curl_init('https://meet77842937.adobeconnect.com/api/xml?action=report-my-meetings');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEFILE, __DIR__.'/cookies');
curl_setopt($ch,CURLOPT_COOKIEJAR, __DIR__.'/cookies');
$data = curl_exec($ch);
var_dump($data);
curl_close($ch);
Read it. It's clear enough.

Creating and inviting a group to an event via graph api

Is there still no way to invite all the group members to an group event? I am able to create the group event via the api, but members are not invited to the new event. If i create the event via the facebook website i have the option to select "invite all group members". I can't seem to find any way to reproduce that functionality via the api.
Since there was no way to do this directly via the graph api i ended up making my own php w/mysql solution. Basically i make a table of all my group's members, then i check if they have been invited to all my group's events. the good thing about this forced method is that if a new members joins after an event is created they will be invited to all future events.
facebook does not tell you how many members you can invite from the api per time period and not get flagged for spam
code to dump group members:
function UpdateFacebookMemberDB($verbatim = FALSE)
{
global $access_token, $groupID;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/members?access_token='.$access_token);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close ($ch);
$decoded = json_decode($return, true);
$decoded = $decoded['data'];
Sql_Connect();
if(!Sql_Query("DELETE FROM `Facebook_User`;"))
{
echo "Could not empty the `Facebook_User` table.<br>\n";
return FALSE;
}
foreach ($decoded as $value)
{
$query="INSERT INTO `Facebook_User` (`Name`, `FID`) VALUES ('".Sql_CleanInput($value['name'])."', '".Sql_CleanInput($value['id'])."');";
if(Sql_Query($query))
{
if($verbatim)
echo $value['name']." was added to the database.<br>";
}
else if($verbatim)
echo $value['name']." was <b>NOT</b> added to the database.<br>";
}
if(!Sql_Query("DELETE FROM `Facebook_Event`;"))
{
echo "Could not empty the `Facebook_Event` table.<br>\n";
return FALSE;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/events?fields=start_time&since=now&access_token='.$access_token);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close ($ch);
$decoded = json_decode($return, true);
$decoded = $decoded['data'];
foreach ($decoded as $value)
{
$eid = $value['id'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$eid.'/invited?access_token='.$access_token);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close ($ch);
$decod = json_decode($return, true);
$decod = $decod['data'];
foreach ($decod as $val)
{
$query="INSERT INTO `Facebook_Event` (`EventID`, `UserID`) VALUES ('".$eid."', '".$val['id']."');";
if(Sql_Query($query))
{
if($verbatim)
echo $val['name']." was added to the database.<br>";
}
else if($verbatim)
echo $val['name']." was <b>NOT</b> added to the database.<br>";
}
}
Sql_Disconnect();
}
code to check/invite members:
function InviteClubToEvent)
{
global $access_token, $groupID;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/events?fields=start_time&since=now&access_token='.$access_token);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close ($ch);
$decoded = json_decode($return, true);
$decoded = $decoded['data'];
$invite=0;
for($x=count($decoded)-1;$x>=0;$x--)
{
$eventid = $decoded[$x]['id'];
Sql_Connect();
$query="SELECT * from `Facebook_User` ORDER BY `FID` ASC;";
$qresult=Sql_Query($query);
$data = array( 'access_token' => $access_token);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
for($i=0;$i<Sql_Num_Rows($qresult);$i++)
{
$subquery="SELECT * from Facebook_Event WHERE `UserID` ='".Sql_Result($qresult,$i,"FID")."' AND `EventID` ='".$eventid."'LIMIT 1;";
if(Sql_Num_Rows(Sql_Query($subquery))==0)
{
$invite++;
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$eventid.'/invited/'.Sql_Result($qresult,$i,"FID"));
$return = curl_exec($ch);
if($return == "true")
{
echo "$invite) ".Sql_Result($qresult,$i,"Name") . " has been invited to $eventid!<br>";
Sql_Query("INSERT INTO `sdbmwcca_main`.`Facebook_Event` (`EventID`, `UserID`) VALUES ('".$eventid."', '".Sql_Result($qresult,$i,"FID")."');");
} else
{
echo "<hr><b>$invite) ".Sql_Result($qresult,$i,"Name") . " was not invited because: " . $return . "</b><hr>";
curl_close($ch);
Sql_Disconnect();
die();
}
}
if($invite > ##some spam limit##)
{
$x = 0;
break;
}
}
curl_close ($ch);
Sql_Disconnect();
}
}

Categories