Skip to content

Instantly share code, notes, and snippets.

@kosso
Created September 2, 2012 03:20
Show Gist options
  • Save kosso/3594512 to your computer and use it in GitHub Desktop.
Save kosso/3594512 to your computer and use it in GitHub Desktop.
Adding annotations to an App.net post using PHP
<?php
// # Adding annotations to an App.net post using PHP
// Kosso - alpha.app.net/kosso
// Do what you like with it.
$ACCESS_TOKEN = 'BLahbLAHl1234BLAHBLAHBLAH';
$post_text = "Hello. This post has annotations";
$ch = curl_init();
// https://github.com/appdotnet/api-spec/blob/master/resources/posts.md#create-a-post
curl_setopt($ch, CURLOPT_URL, "https://alpha-api.app.net/stream/0/posts");
$jdata = Array();
$jdata['text'] = $post_text;
$annotations = Array();
$annotations['type'] = 'com.your.namespace';
$anno_value = Array();
$anno_value['foo'] = 'bar';
$anno_value['something'] = 'ELSE';
$annotations['value'] = $anno_value;
$jdata['annotations'][0] = $annotations;
$jdata_string = json_encode($jdata);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jdata_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$ACCESS_TOKEN,
'Content-Type: application/json',
'Content-Length: ' . strlen($jdata_string))
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment