I can successfully post a message. However when I try with a chart, I get back a success code (200) with the following URL's in the response:
http://charts.stocktwits.com/production/large_.png
http://charts.stocktwits.com/production/small_.png
When I Try to view the message in StockTwits, I get image not found
http://stks.co/p2kuK
I assume there should be some code after large_ and small_; hence the image not found.
Since no errors came back in JSON Response, I assume everything worked OK.
Link to Chart I'm uploading with API:
http://tradescribe.com/images/performance_graphs/AStrakaus-3GTakeover-5day.png
Any ideas?
The message appears in StockTwits without the Chart so API call looks to be correct
Code
$postdata = array(
'access_token' => <TOKEN>,
'body' => <MESSAGE INFORMATION>,
'chart' => <FULLY QUALIFIED URL TO IMAGE>
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://api.stocktwits.com/api/2/messages/create.json',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $postdata
));
We have fixed an issue on our end that was causing this problem and shouldn't be happening anymore.
Related
I am trying to submit a post with JSON content. I always get this message back:
"Client
error: POST
https://sandbox-api-ca.metrc.com//strains/v1/create?licenseNumber=CML17-0000001
resulted in a 400 Bad Request response: {"Message":"No data was
submitted."}"
(All keys and license number are sandbox. I changed keys slightly so auth wont work. )
here is my code
public function metrc()
{
$client = new Client();
$url = 'https://sandbox-api-ca.metrc.com//strains/v1/create?licenseNumber=CML17-0000001';
$request = $client->post($url, [
'headers' => ['Content-Type' => 'application/json'],
'json' => ['name' => "Spring Hill Kush"],
'auth' => ['kH-qsC1oJPzQnyWMrXjw0EQh812jHOX52ALfUIm-dyE3Wy0h', 'fusVbe4Yv6W1DGNuxKNhByXU6RO6jSUPcbRCoRDD98VNXc4D'],
]);
}
Your code is correct, it should works as expected. Seems that the issue is on the server side. Maybe the format of the POST request is not correct?
BTW, 'headers' => ['Content-Type' => 'application/json'] is unnecessary, Guzzle sets the header by itself automatically when you use json option.
I am using the the Facebook Marketing API to upload offline conversions.
The attached code was working until about 2 weeks ago and now reports the following error.
{"error":{"message":"(#100) The parameter data is required","type":"OAuthException","code":100,"fbtrace_id":"HkpzkWB1I5g"}}
I don't understand why it should simply stop working after working as expected for so long. I don't know how to fix it. Any ideas?
$data=array();
$data["match_keys"]["email"]=$emails;
$data["match_keys"]["phone"]=$mobiles;
$data["match_keys"]["fn"]=hash("sha256",$first_name);
$data["match_keys"]["ln"]=hash("sha256",$last_name);
$data["match_keys"]["ln"]=hash("sha256",$last_name);
$data["match_keys"]["ct"]=hash("sha256",$suburb);
$data["match_keys"]["zip"]=hash("sha256",$postcode);
$data["match_keys"]["country"]=hash("sha256","Australia");
$data["event_time"] = strtotime($order_date);
$data["event_name"] = "Purchase";
$data["currency"] = "AUD";
$data["value"] = $order_total;
$data['order_id']=$order_id;
$access_token = '<access_token_0>';
// PURCHASE DATA
$data_json = json_encode(array($data));
$fields = array();
$fields['access_token'] = $access_token;
$fields['upload_tag'] = uniqid() // You should set a tag here (feel free to adjust)
$fields['data'] = $data_json;
$ch = curl_init();
curl_setopt_array($ch, array(
// Replace with your offline_event_set_id
CURLOPT_URL => "https://graph.facebook.com/v2.12/1696501357346693/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($fields),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data",
"Accept: application/json" ),
));
$result = curl_exec($ch);
echo "\nResult encode";
echo ($result);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Same thing just started happening here. Exact same problem. I had to play around for hours... But to get it working, I commented out
//"content-type: multipart/form-data",
and it started to work for me. Please let know if that also solves your problem.
It simply means that data is not sent as per documentation. I was facing this issue as in my case "contents" parameter was passing empty string, instead of documentation says that "contents" parameter should contain atleast 2 parameters, that is, quantity and id.
Go through documentation and you can compare your value format with documentation.
Here is link for documentation :- https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data#content-ids
I'm having trouble uploading a file to facebook with PHP versions before 5.5 where CURLFile class is not available.
As I understand, I should use #filepath as the source and that should work, but for some reason it returns
Exception occured, code: 353 with message: (#353) You must select a video file to upload.
I've tried sending the path using realpath() function, that doesn't work.
$response = (new FacebookRequest(
$session, 'POST', '/me/videos', array(
'source' => '#'.realpath($url),
'description' => $description,
'title' => $title
)
))->execute()->getGraphObject();
Does anyone have a solution for this?
I've upgraded to Zend Framework v1.12.3 because it supports the TwitterAPI v1.1 with Zend_Service_Twitter. Before, I've used the TwitterAPI 1.0 (prior ZF 1.12.3) which works well, but that's gonna change in march 2013.
If I call the TwitterAPI v1.1 with the following ZF 1.12.3 code, I keep getting a strange error which I can't explain to myself:
Code:
$twitterService = new Zend_Service_Twitter(array(
'consumerKey' => $this->config['consumerKey'],
'consumerSecret' => $this->config['consumerSecret'],
'username' => $twitterVO->getTwitterUserName(),
'accessToken' => $accessToken // unserialized object
));
$response = $twitterService->statusesUpdate("TEST");
And that's the error which I get. It doesn't matter which function I call (in this case it's statusesUpdate("Test")):
The message is "Invalid chunk size "" unable to read chunked body". The "type" attribute within the array shows a "->". That's also a bit suspect but I couldn't find out where it comes from.
Does anyone have a working example with Zend Framework 1.12.3?
Since ZF 1.12, the Twitter app Oauth parameters can be given in the Zend_Service_Twitter constructor, but consumerKey and consumerSecret must go under the "oauthOptions" array.
This works for me:
$accessToken = new Zend_Oauth_Token_Access();
$accessToken->setToken('YourAccessToken');
$accessToken->setTokenSecret('YourAccessTokenSecret');
$twitter = new Zend_Service_Twitter(
array(
'username' => 'YourUsername',
'accessToken' => $accessToken,
'oauthOptions' => array(
'consumerKey' => 'YourConsumerKey',
'consumerSecret' => 'YourConsumerSecret'
)
)
);
$result = $twitter->statusesUserTimeline('TEST');
I've written a script that authenticates against Google's OAuth API for Latitude, using Net::OAuth. It correctly authenticates (as I can successfully fetch data out of the API). However, when I try to add an historical entry, I get a 401 Unknown authorization header response. I'm using the following code:
my $location_data = $json->encode(\%data);
$request = Net::OAuth->request("protected resource")->new(
consumer_key => $c_key,
consumer_secret => $c_secret,
token => $token,
token_secret => $token_secret,
verifier => $verifier,
request_url => 'https://www.googleapis.com/latitude/v1/location',
request_method => 'POST',
signature_method => $s_method,
timestamp => time,
nonce => &nonce(),
extra_params => {
key => $s_key
}
);
$request->sign;
$ua->default_header("Authorization", $request->to_authorization_header);
$ua->default_header("Content-Type", "application/json");
my $res = $ua->post('https://www.googleapis.com/latitude/v1/location?key=' . $s_key,
Content => $location_data);
All of the variables are used in the fetch portion of the API, so I know those are all ok. I'm not sure if I'm using the correct URL to post against, and I've tried what's in the sample above, as well as $request->to_url.
Any suggestions would be greatly appreciated.
After some back and forth with the Latitude API team, it was determined that this error comes from the fact that the Content-Type is not actually being set to application/json. Changing the above code to:
$ua->default_header("Authorization", $request->to_authorization_header);
my $res = $ua->post('https://www.googleapis.com/latitude/v1/location?key=' . $s_key,
'Content-Type' => 'application/json',
Content => $location_data);
And everything works as expected.