public function post_on_wall($title, $message, $user_id){
$token = json_decode(Tokens::get_token($user_id));
$url = "https://api-yaru.yandex.ru/person/{$user_id}/post/";
$data = array(
'oauth_token' => $token->oauth_token,
'format' => 'json',
'title' => $title,
'content' => $message
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-yaru-atom+json; type=entry\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dum($result);
}
public function post_on_wall($title, $message, $user_id){
$token = json_decode(Tokens::get_token($user_id));
$data = array(
'oauth_token' => $token->oauth_token,
'format' => $token->format,
'title' => $title,
'content' => $message
);
$url = "https://api-yaru.yandex.ru/person/{$user_id}/post/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url.'?'.urldecode(http_build_query($data)));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, urldecode(http_build_query($data)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, THIS, false);
$result = curl_exec($curl);
curl_close($curl);
var_dump($result);
}
$(document).ready(function(){
$.ajax({
dataType: 'jsonp',
type: 'POST',
data: {'oauth_token': '{token}', 'format': 'json', 'title': 'Title', 'content': 'Content'},
url: 'https://api-yaru.yandex.ru/person/{user_id}/post/',
success: function(r) {console.dir(r);},
error: function(e) {console.log(e);}
});
});
$post_data = array(
'oauth_token' => 'oauth_token',
'title' => 'title',
'content' => 'content'
);
$result = post_request('api-yaru.yandex.ru/person/{uid}/post/?format=json', $post_data);
if ($result['status'] == 'ok'){
// Print headers
echo $result['header'];
echo '<hr>';
// print the result of the whole request:
echo $result['content'];
}
else {
echo 'A error occured:' . $result['error'];
}
protected function _request()
{
$params = array(
'http' => array(
'method' => $this->method,
'header' => sprintf("Authorization: OAuth %s\r\n", $this->token).
sprintf("Content-Type: %s\r\n", $this->contentType),
'content' => $this->content
)
);
$ctx = stream_context_create($params);
$fp = fopen($this->url, 'r', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $this->url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $this->url, $php_errormsg");
}
return $response;
}
Find more questions by tags Yandex
- chelsie_Kessler commented on October 3rd 19 at 02:48
- chelsie_Kessler commented on October 3rd 19 at 02:54
- erick.Lind commented on October 3rd 19 at 02:57
Have done so:
The result is identical:( - erick.Lind commented on October 3rd 19 at 03:03