I am trying to create a phonegap app by using their createapp build API as described in
http://docs.build.phonegap.com/en_US/developer_api_write.md.html
<?php
$data = array(
"file" => "#http://mywebsite.com/tmp/www.tar.gz",
//"file" => "#actual path to/www.tar.gz",
"data" => '{"title":"MyTestApp","create_method":"file"}'
);
$myusername = 'my build.phonegap user id';
$password = 'my build.phonegap password';
$handle = curl_init();
curl_setopt($handle, CURLOPT_USERPWD, $myusername.':'.$password);
curl_setopt($handle, CURLOPT_URL, "https://build.phonegap.com/api/v1/apps");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, array(
'Content-type: multipart/form-data;',
));
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($handle);
print_r($response);
?>
The www.tar.gz file is a valid file and it can be even download from the URL.
The code shows the below error
{"error":"Unable to create app: input is not a file"}
I raised this with phonegap support website and It looks my question doesn't get anyone's attention there. :-(
https://c.getsatisfaction.com/nitobi/topics/unable-to-create-app-input-is-not-a-file-df668pmjm93np
Thanks #mradionov at https://github.com/mradionov/phonegap-build-api/issues/3
The problem is just because of the cURL changed in php and nothing to do with the phonegap api releases.
It looks the file upload method via curl got changed in php 5.6 version.
The below solved the issue
<?php
$data = array(
"file" => new CurlFile("path to the file/abcd.tar.gz"),
"data" => '{"title":"MyTestApp","create_method":"file"}'
);
$myusername = 'phonegap user id';
$password = 'phonegap password';
$handle = curl_init();
curl_setopt($handle, CURLOPT_USERPWD, $myusername.':'.$password);
curl_setopt($handle, CURLOPT_URL, "https://build.phonegap.com/api/v1/apps");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, array(
'Content-type: multipart/form-data;',
));
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($handle);
print_r($response);
?>
In case if we use the OAuth then use the below
<?php
$data = array(
"file" => new CurlFile("path to file/abcd.tar.gz"),
"data" => '{"title":"MyTestApp","create_method":"file"}'
);
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, "https://build.phonegap.com/api/v1/apps?access_token=accesstoken");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, array(
'Content-type: multipart/form-data;',
));
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($handle);
print_r($response);
?>
#Malaiselvan,
Phonegap 2.x is obsolete. It is no longer supported. None of those examples work any longer.
As of 23 Sep 2015, the blog post is entitled PhoneGap 5.2.0 Now Available on Build.
The means we are on Phonegap version 5.x.
If you want build your own remote IDE, then you want to use this documentation
http://docs.build.phonegap.com/en_US/developer_api_api.md.html#PhoneGap%20Build%20Developer%20API
Best of Luck
Related
I'm trying to add a new user to my Vanilla forum and unfortunately I don't understand what's wrong with my code. GET request to read user data works fine butPOST requests result in a "bool(false)".
As I understand it, that's already a response from the API, which obviously can't do anything with my request, right?
But what's wrong with that? Do I have to somehow send the JSON data as a 'body'? Anyone have an idea? Thank you!!!
This is what my code currently looks like:
<?php
// post with absolute url = Invalid CSRF token error
// $url = "https://example.com/app/vanilla/api/v2/users";
$url = "/app/vanilla/api/v2/users";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
$headers = array(
"Accept: application/json",
"Authorization: Bearer {va.jOh189hry7463klur_kcw8UomJU36782.HGqvdQ.RQon456}"
);
$data = array(
'bypassSpam' => 'false',
'email' => 'info#mysite.de',
'emailConfirmed' => 'true',
'name' => 'Theo Tester',
'password' => '1234567890',
'photo' => '',
'roleID' => [33]
);
$payload = json_encode(array($data));
// Attach encoded JSON string to the POST fields
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
// Set the content type to application/json
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// Return response instead of outputting
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
This is what the vanilla API documentation looks like (please see picture below or link):
(https://success.vanillaforums.com/kb/articles/202-api-v2-reference-endpoints#/Users/post_users)
And this just for completeness is the code for GET requests as it works for me:
<?php
$url = "https://example.com/app/vanilla/api/v2/roles";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Accept: application/json",
"Authorization: Bearer {va.jOh189hry7463klur_kcw8UomJU36782.HGqvdQ.RQon456}",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
I want to upload the media via Whatsapp cloud API in order to send the media to WhatsApp, I have followed the link below, but having the stated issue.
https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#get-media-id
Array ( [error] => Array ( [message] => (#100) The parameter messaging_product is required. [type] => OAuthException [code] => 100 [fbtrace_id] => AQPftb9Bf343375gQ_QytxNen ) ) 400
My Code is
// #1640191015925.jpg on my root folder
$post = [
'file' => '#1640191015925.jpg;type=image/jpeg',
'messaging_product' => 'whatsapp'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v13.0/Phone-Number-ID/media');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$YOUR_WHATSAPP_ACCESS_TOKEN = '+++++++';
$headers[] = "Authorization: Bearer $YOUR_WHATSAPP_ACCESS_TOKEN";
$headers[] = "Content-Type: image/jpeg";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = json_decode(curl_exec($ch), true);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//$MEDIA_OBJECT_ID = $result['media'][0]['id']; //MEDIA OBJECT ID
print_r($result);
print_r($httpcode);
?> ```
I had the same issue, after some digging around I wrote this function to upload a file and return the id.
function waFileUploader($token, $file, $senderid){
$mime = mime_content_type($file);
$info = pathinfo($file);
$name = $info['basename'];
$curlfile = new CURLFile($file, $mime, $name);
$filedata = array("messaging_product"=>"whatsapp", "file" => $curlfile);
$url = 'https://graph.facebook.com/v13.0/' . $senderid . '/media';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Authorization: Bearer $token", "Content-Type: multipart/form-data"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $filedata);
$r = curl_exec($ch);
curl_close($ch);
$id = json_decode($r, true);
return $id["id"];
}
I am new to cURL from PHP. I am trying to send file URL as post field and API Key as header to the background remover API to retrieve the background removed image. The error says:
{"errors":[{"title":"No image given","code":"missing_source","detail":"Please provide the source image in the image_url, image_file or image_file_b64 parameter."}]}
My code:
<?php
$url='https://api.remove.bg/v1.0/removebg';
$ch = curl_init($url);
$data = array('image_url'=> 'https://www.requestingservicebyme.com/upload/imageexample.jpg');
$headers1=['X-API-Key:xxxxxxxxxxxxxxx',
'Content-Type:application/json'];
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$buffer = curl_exec($ch);
if (empty($buffer)) {
echo " buffer is empty ";
} else{
echo $buffer;
}
curl_close($ch);
?>
I was also working on it using the curl I got success in that ..!
Change your headers
Remove the application type json from headers as this api returns the data in Image content format.
$x = curl_init();
$headers=['X-API-Key:xxxxxxxxxxxxxxxxx'];
$data = array (
'image_url' => "https://amblin.com/wp-content/uploads/2019/09/castaway_2000_photo_29.jpg",
'size' => "auto",
);
$url = 'https://api.remove.bg/v1.0/removebg';
// $post = http_build_query($data);
$x = curl_init($url);
curl_setopt($x, CURLOPT_POST, true);
curl_setopt($x, CURLOPT_RETURNTRANSFER, true);
curl_setopt($x, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($x, CURLOPT_HTTPHEADER, $headers);
curl_setopt($x, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($x, CURLOPT_POSTFIELDS, $data);
$y = curl_exec($x);
curl_close($x);
//And then save it using this code
$fp = fopen("result.jpg", "wb");
fwrite($fp, $y);
fclose($fp);
I am having some issue running the api to send email with attachment via Mail Gun.I tried to run the api via postman and it runs perfectly fine so i know there is no problem with the api but i am unable to send a request via code.
I have added a code sample below:
<?php
$curl_post_data=array(
'from' => 'Excited User <noreply#test.com>',
'to' => 'test#gmail.com',
'subject' => 'Hello',
'text' => 'test'
//,'attachment[1]' => '#https://www.smsglobal.com/docs/HTTP-2WAY.pdf'
,array( 'attachment' => 'https://www.smsglobal.com/docs/HTTP-2WAY.pdf')
);
$service_url = 'https://api.mailgun.net/v3/test.com/messages';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "api:key-testtesttesttes");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
$response = json_decode($curl_response);
curl_close($curl);
var_dump($response);
?>
I was able to solve the issue.
My Findings:
1-) You cannot give a live url address as attachment http://test.com/images/logo.png will not work.
2-) only address of files hosted on the server can be given
/var/images/logo.png
<?php
$filePath='#0Wealth_AC_AMF.pdf';
$curl_post_data=array(
'from' => 'Excited User <noreply#test.com>',
'to' => 'test#gmail.com',
'subject' => 'Hello',
'text' => 'test',
'attachment[1]' => $filePath
);
$service_url = 'https://api.mailgun.net/v3/test.com/messages';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "api:key-test");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
$response = json_decode($curl_response);
curl_close($curl);
var_dump($response);
?>
I'm trying to edit Eventbrite event using version 3 of the API but I always returns false.
$request_url = 'https://www.eventbriteapi.com/v3/events/xxxxxx';
$options = array(
'http' => array(
'method' => 'POST',
'header'=> "Authorization: Bearer xxxxxxxxxx"
),
'name' => array(
'text'=>'Hi',
'html'=>'<p>Hi</p>'
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$json_data = curl_exec($ch);
$resp_info = curl_getinfo($ch);
curl_close($ch);
var_dump($json_data);
This always returns me :
boolean false
What am I doing wrong?
You don't need to create an options array with curl as you are setting those options in curl_setopt. Just make a data array and submit it.
<?php
$request_url = 'https://www.eventbriteapi.com/v3/events/xxxxxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
'name' => array(
'text'=>'Hi',
'html'=>'<p>Hi</p>'
)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$json_data = curl_exec($ch);
$resp_info = curl_getinfo($ch);
curl_close($ch);
var_dump($json_data);
Though according to the docs there is a minimum amount of data to create an event.