54 lines
7.6 KiB
HTML
54 lines
7.6 KiB
HTML
<!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/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.8.13"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>mastodon-cpp: example2_parse_account.cpp</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">mastodon-cpp
|
|
 <span id="projectnumber">0.5.0</span>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.13 -->
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
$(function() {
|
|
initMenu('',false,false,'search.php','Search');
|
|
});
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">example2_parse_account.cpp</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="fragment"><div class="line"><span class="comment">/* This file is part of mastodon-cpp.</span></div><div class="line"><span class="comment"> * This example parses your account data and prints it out in a readable way.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <iostream></span></div><div class="line"><span class="preprocessor">#include <vector></span></div><div class="line"><span class="preprocessor">#include <string></span></div><div class="line"><span class="preprocessor">#include <cstdint></span></div><div class="line"><span class="preprocessor">#include <sstream></span></div><div class="line"><span class="preprocessor">#include <boost/property_tree/ptree.hpp></span></div><div class="line"><span class="preprocessor">#include <boost/property_tree/json_parser.hpp></span></div><div class="line"><span class="preprocessor">#include "../mastodon-cpp.hpp"</span></div><div class="line"></div><div class="line"><span class="keyword">using</span> <a name="_a0"></a><a class="code" href="classMastodon_1_1API.html">Mastodon::API</a>;</div><div class="line"><span class="keyword">namespace </span>pt = boost::property_tree;</div><div class="line"><span class="keyword">using</span> std::cout;</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line">{</div><div class="line"> <span class="keywordflow">if</span> (argc < 3)</div><div class="line"> {</div><div class="line"> std::cerr << <span class="stringliteral">"usage: "</span> << argv[0] << <span class="stringliteral">" <instance> <access token>\n"</span>;</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> }</div><div class="line"></div><div class="line"> <a class="code" href="classMastodon_1_1API.html">Mastodon::API</a> masto(argv[1], argv[2]);</div><div class="line"> std::string answer;</div><div class="line"> std::uint16_t ret;</div><div class="line"></div><div class="line"> ret = masto.<a name="a1"></a><a class="code" href="classMastodon_1_1API.html#a1d4ace331be12e5234246bc274c0dddd">get</a>(API::v1::accounts_verify_credentials, answer);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0)</div><div class="line"> {</div><div class="line"> std::istringstream iss(answer);</div><div class="line"> pt::ptree tree;</div><div class="line"> </div><div class="line"> pt::read_json(iss, tree);</div><div class="line"> std::string uid = tree.get<std::string>(<span class="stringliteral">"id"</span>);</div><div class="line"> cout << <span class="stringliteral">"Your ID is: "</span> << uid << <span class="charliteral">'\n'</span>;</div><div class="line"> cout << <span class="stringliteral">"Your whole acount tree:\n"</span>;</div><div class="line"> </div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> pt::ptree::value_type &v : tree.get_child(<span class="stringliteral">""</span>))</div><div class="line"> {</div><div class="line"> cout << <span class="stringliteral">" "</span>;</div><div class="line"> <span class="keywordflow">if</span> (v.second.size() > 0)</div><div class="line"> {</div><div class="line"> cout << v.first.data() << <span class="stringliteral">": \n"</span>;</div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> pt::ptree::value_type &vc : v.second.get_child(<span class="stringliteral">""</span>))</div><div class="line"> {</div><div class="line"> cout << <span class="stringliteral">" "</span>;</div><div class="line"> cout << vc.first.data() << <span class="stringliteral">": "</span> << vc.second.data() << <span class="charliteral">'\n'</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> {</div><div class="line"> cout << v.first.data() << <span class="stringliteral">": "</span> << v.second.data() << <span class="charliteral">'\n'</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ret == 13)</div><div class="line"> {</div><div class="line"> std::cerr << <span class="stringliteral">"The URL has permanently changed.\n"</span> <<</div><div class="line"> <span class="stringliteral">"New URL: "</span> << answer << <span class="charliteral">'\n'</span>;</div><div class="line"> <span class="keywordflow">return</span> ret;</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> {</div><div class="line"> std::cerr << <span class="stringliteral">"Error code: "</span> << ret << <span class="charliteral">'\n'</span>;</div><div class="line"> <span class="keywordflow">return</span> ret;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.13
|
|
</small></address>
|
|
</body>
|
|
</html>
|