2018-06-07 19:28:24 +02:00
|
|
|
<!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.14"/>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
|
|
<title>mastodon-cpp: example05_follow_unfollow.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
|
2019-02-19 08:58:16 +01:00
|
|
|
 <span id="projectnumber">0.30.1</span>
|
2018-06-07 19:28:24 +02:00
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
<!-- end header part -->
|
|
|
|
<!-- Generated by Doxygen 1.8.14 -->
|
|
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
|
|
$(function() {
|
|
|
|
initMenu('',false,false,'search.php','Search');
|
|
|
|
});
|
|
|
|
/* @license-end */</script>
|
|
|
|
<div id="main-nav"></div>
|
|
|
|
</div><!-- top -->
|
|
|
|
<div class="header">
|
|
|
|
<div class="headertitle">
|
|
|
|
<div class="title">example05_follow_unfollow.cpp</div> </div>
|
|
|
|
</div><!--header-->
|
|
|
|
<div class="contents">
|
2018-12-04 11:34:47 +01:00
|
|
|
<div class="fragment"><div class="line"><span class="comment">/* This file is part of mastodon-cpp.</span></div><div class="line"><span class="comment"> * Follow someone, then unfollow.</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 <chrono></span></div><div class="line"><span class="preprocessor">#include <thread></span></div><div class="line"><span class="preprocessor">#ifdef MASTODON_CPP</span></div><div class="line"><span class="preprocessor"> #include "mastodon-cpp.hpp"</span></div><div class="line"><span class="preprocessor">#else</span></div><div class="line"><span class="preprocessor"> #include <mastodon-cpp/mastodon-cpp.hpp></span></div><div class="line"><span class="preprocessor">#endif</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"></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"> masto.<a name="a1"></a><a class="code" href="classMastodon_1_1API.html#ae25c5e6eabb8e783d7034ee1c79ae741">set_useragent</a>(<span class="stringliteral">"mastodon-cpp-example/1.3.3.7"</span>);</div><div class="line"> std::string answer;</div><div class="line"> std::uint16_t ret;</div><div class="line"> std::string id;</div><div class="line"></div><div class="line"> std::cout << <span class="stringliteral">"Follow [ID or username@domain]: "</span>;</div><div class="line"> std::cin >> id;</div><div class="line"></div><div class="line"> <span class="comment">// If no @ is found, it is presumably an ID</span></div><div class="line"> <span class="keywordflow">if</span> (<span class="keywordtype">id</span>.find(<span class="charliteral">'@'</span>) == std::string::npos)</div><div class="line"> {</div><div class="line"> ret = masto.<a name="a2"></a><a class="code" href="classMastodon_1_1API.html#aaf5ba9253c05c733bc6a7819fd7455cd">post</a>(API::v1::accounts_id_follow, {{<span class="stringliteral">"id"</span>, {<span class="keywordtype">id</span>}}}, answer);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0)</div><div class="line"> {</div><div class="line"> <span class="comment">// std::cout << answer << '\n';</span></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</
|
2018-06-07 19:28:24 +02:00
|
|
|
<!-- 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.14
|
|
|
|
</small></address>
|
|
|
|
</body>
|
|
|
|
</html>
|