Create a team/organizations via trello api - php

I want to create trello teams automatically via an html form from my website.
I wrote a php script that seems to work. For example I can get list of boards or create a new board. But it does not works to create teams.
HTML CODE
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="api_method.php" method="post">
Project Name:<br>
<input type="text" name="projectName" value="board_test">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "api_method.php".</p>
</body>
</html>
I then use a php script to create the new board:
<?php
require("trello_api.php");
$key = 'mykey';
$token = 'mytoken';
$trello = new trello_api($key, $token);
$data = $trello->request('GET', ('member/me/boards'));
$obj = array('name' => $_POST['projectName']);
$trello->request('POST', ('/boards'),$obj);
echo "Board name: " . $data[0]->name . "\n \n";
echo "New board: " . $_POST['projectName'];
?>
So that works perfectly but not when I try to do the same thing with "organizations" it doesn't work
$trello->request('POST', ('/organizations'),$obj);
Can you please help me.

I found the solution, I had to use the option "displayName" instead of "name"
<?php
require("trello_api.php");
$key = 'myKey';
$token = 'myToken';
$trello = new trello_api($key, $token);
$data = $trello->request('GET', ('member/me/boards'));
$obj = array('displayName' => $_POST['projectName']);
$trello->request('POST', ('/organizations'),$obj);
echo "Board name: " . $data[0]->name . "\n \n";
echo "New board: " . $_POST['projectName'];
?>

Related

PHP FILTER_INPUT not receiving text input

I'm running an Apache server on MAMP on macOSX. The problem I've occurred is that every variable is receiving the filter_input() but the last one, "param". I've tried using $_POST['param']; to no avail. I've restarted the Apache server but nothing has changed. I'm sure it's a syntax error, but all the other questions on here are unrelated and unhelpful. The one "PHP form not receiving inputs" was no help at all. Any help is appreciated :)
EDIT: I've realized using filter_input(INPUT_POST, "param") was not needed since I don't provide a filter, and that $_POST["param"] is a more acceptable method.
My HTML:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Code Writer (JAVA)</title>
</head>
<body>
<center>
<h1>Code Writer (JAVA)</h1>
</center>
<form action="backwards.php" method="post">
<fieldset>
<label>Enter visibility level (public/private/etc)</label>
<input type="text" name="first"><br>
<label>Static Method? Y/N</label>
<input type="text" name="static"><br>
<label>Enter return type (int/double/etc)</label>
<input type="text" name="return"><br>
<label>Enter method name?</label>
<input type="text" name="method"><br>
<label>Paramaters, if any</label>
<input type="text" name="param"><br>
<button type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
My PHP:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>backwards.php</title>
</head>
<body>
<?php
#Gather inputs
$first = filter_input(INPUT_POST, "first");
$static = filter_input(INPUT_POST, "static");
$return = filter_input(INPUT_POST, "return");
$method = filter_input(INPUT_POST, "method");
$param = filter_input(INPUT_POST, "param");
#Add to $output
$output = $first . " ";
if ($static == "Y") {
$output .= "static" . " ";
}
$output .= $return . " ";
$output .= $method . "(";
$output .= $param;
$output .= ") {} \n";
#Print $output
print($output);
?>
</body>
</html>
Turns out that right after running the website with #John Conde's comment "var_dumb($_POST)", it started working. Removing the var_dump and it still works, although I am confused as to why. The matter is resolved, but I'm still confused as to why it works now, and not before.

PHP post json result to custom url

By default on my web service I must make a post request to custom user's url. I can post the array but I would like to post request as a json payload, the code below could be the post data, but I cannot get the data from PHP.
function redirect_to_customer($result = [], $redirect_url = "")
{
$html = '<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body onload="closethisasap();">
<form name="redirectpost" method="POST" action="' . $redirect_url . '">
';
if (!is_null($result)) {
$result = json_encode($result);
$html .= '<input type="hidden" value="' . str_replace('"', "'", $result) . '"> ';
}
$html .= "
</form>
</body>
<script type=\"text/javascript\">
function closethisasap() {
document.forms[\"redirectpost\"].submit();
}
</script>
</html>";
echo $html;
}
result of this code is :
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
</head>
<body onload = "closethisasap();">
<form name = "redirectpost" method = "POST" action = "http://www.sample.com/response.php">
<input type = "hidden" value = "{'code':'-103','message':'order_id must be unique'}">
</form>
</body>
<script type = "text/javascript">
function closethisasap()
{
document . forms["redirectpost"] . submit();
}
</script>
</html>
response.php user's file content :
<?php
print_r($_POST);
?>
after post data i get empty array
All inputs including <input type = "hidden" need a name, so name = "something".

Retrieving data from textarea php

I cannot seem to retrieve the data input into this text area. Also I know this code may not be secure, but I am just beginning with php.
echo '<tr><td align=right>Description:</td><td><textarea name=description form=description cols=100 rows=5></textarea></td></tr>';
$descriptionToSend = $("#description").val()
DBSubmit("INSERT INTO Conference (conferenceid,description,submission_due,review_due) VALUES ('".$_POST['conferenceName']."', '" . $descriptionToSend . "','" .$_POST['submitdeadline'] . "','" .$_POST['reviewdeadline']. "')");
Are you mixing up jquery with php ?
First, the <textarea> should reside in a <form>
After the form is submitted to php, you can access the data sent with $_REQUEST['description'] so you would have
$descriptionToSend = $_REQUEST['description'];
<html>
<head>
<title>Test</title>
</head>
<body>
<?php $name = 'nick';
?>
<form action="Test.php">
Name: <input type="text" name="name" value="<?php echo $name; ?>">
About Me: <textarea name="about" rows="5" cols="10"><?php echo $comment; ?></textarea><br/>
Click Me: <input type="submit" vaule="submit">
</body>
</html>
Use $comment to set text and then just retrieve value using $_GET['about'] in next page
<html>
<body>
<?php
$about = $_GET['about'];
echo $about;
?>
</body>
</html>

how to resolve OAuthException: (#100)

I use my recently develop fb app to post on my wall and its shows the following error
Uncaught OAuthException: (#100) picture URL is not properly formatted thrown in
you can also see this directly *https://apps.facebook.com/hack-proof_pages/1gp.html
using two files "1gp.html" and "gp1.php"
1gp.html code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="gp1.php">
<p>message
<textarea style="width:300px; height:50px;" name="message1"></textarea>
</p>
<p>link
<input type="text" style="width:300px;" name="link1" />
</p>
<p>
Picture
<input type="text" name="picture1" />
</p>
<p>
name
<input type="text" style="width:300px;" name="name1" />
</p>
<p>
Caption
<input type="text" style="width:300px;" name="caption1" />
</p>
<p>Description
<textarea style="width:300px; height:50px;" name="description1"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
gp1.php code
<?php
require_once 'library/facebook.php';
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => '149865361795547',
'secret' => 'shhhh seceret :)',
'cookie' => true,
));
$app_id = '149865361795547';
$canvas_page = "https://apps.facebook.com/hack-proof_pages/gp1.php";
//get data for post
$message1 = $_POST['message1'];
$picture1 = $_POST['picture1'];
$name1 = $_POST['name1'];
$link1 = $_POST['link1'];
$caption1 = $_POST['caption1'];
$description1 = $_POST['description1'];
// compile the post for for user
$WallPost = array(
'message' => $message1,
'link' => $link1,
'picture' => $picture1,
'name' => $name1,
'caption' => $caption1); // you can also use 'picture', 'link', 'name', 'caption', 'description', 'source'....
//http://developers.facebook.com/docs/reference/api/
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page) . ("&scope=email,read_stream,publish_stream,offline_access,publish_actions,manage_pages,user_groups&response_type=token");
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
//getting the userid and some other data for verification
//get the user id
$UserId = $data["user_id"];
echo 'UserId;' . $UserId;
//get the user access token
$atoken = $facebook->getAccessToken();
echo "</br>" . 'User Access_Token:' . $atoken;
//set default access token and profile
//$facebook->setAccessToken($atoken);
//$user_profile = $facebook->api('/me');
//get the user name and email
$user_id = $facebook->getUser();
$user_profile = $facebook->api('/me','GET');
$user_name = $user_profile['name'];
echo "Name: " . $user_name;
$user_email = $user_profile['email'];
echo "email: " . $user_email;
// post to user wall
$response = $facebook->api('/me' . '/feed','POST',$WallPost);
//posting to groups wall with sleeping time support poster.xls
}
?>
*Note: my app use self signed certificate SSL so that if you want to test this above URL you need to allow my site and store its certificate and one more info that sometimes google chrome shows error due to google chrome one weak point that chrome needs to store self signed certificate in internet explorer means if you want to check this in chrome you need to first open this site in internet explorer and allow my site self signed certificate and store permanently so that its also work in chrome
Please check your picture url, you need to give the full url of the photo not the relative url and facebook should be able to access the picture url, i.e. it should not be of your locally hosted application, try placing a fully qualified sample url of any picture in ur code and check.

flickr.photos.search

I would like to ask for help. I got this homework to create a class in PHP with search method which returns 50 pictures from Flickr, but without use of official PHP Flickr libraries... Anyway with help of google I wrote following code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
class Flickr {
private $apiKey = 'aba429532a6606f2ee35e3f47a300716';
public function search($query = null) {
$search = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apiKey . '&text=' . urlencode($query) . '&per_page=50&format=php_serial';
$result = file_get_contents($search);
$result = unserialize($result);
return $result;
}
}
?>
<form action="index.php" method="get">
<input type="text" name="text1" /><br />
<input type="submit" name="submit1" value="Send" /><br />
</form>
<?php
if(isset($_GET["submit1"])) {
$Flickr = new Flickr;
$data = $Flickr->search($_GET["text1"]);
foreach($data['photos']['photo'] as $photo) {
echo '<img src="http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">';
}
}
?>
</body>
</html>
That code does what I need, but I am not sure whether I can use flickr.photos.search, so I was wondering if there is a way to avoid using flickr.photos.search.
You could just request http://www.flickr.com/search/?q={work_by_witch_you_search}&z=m pictures from here with curl and just parse received page. Then you definitely wount use anything even close to Flickr API.

Categories