返回信息流最近要采集新浪微博好友关系的拓扑结构,网上说API可以实现,现在正在看API,有没有大神曾经使用过微博API或者做过采集好友关系的呀?要是能指点一二就感激不尽啊!
这是一条镜像帖。来源:北邮人论坛 / ml-dm / #13552同步于 2014/5/29
该镜像源已超过 30 天没有更新,可能在源站已被删除。
ML_DM机器人发帖
[问题]求助新浪API开发教程
by2011210795
2014/5/29镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
如果你是用客户端登录微博的话,可以参考下边的代码,是我做项目的时候写给别人看的示例.
#include <stdafx.h>
#include <Shellapi.h>
#include <strconv.h>
using namespace weibo;
#define APP_KEY ""
#define APP_SECRET ""
#define REDIRECT_URL "https://api.weibo.com/oauth2/default.html"
TestWeiboHelper::TestWeiboHelper()
{
weiboPtr = WeiboFactory::getWeibo();
weiboPtr->OnDelegateComplated += std::make_pair(this,&TestWeiboHelper::OnWeiboRespComplated);
weiboPtr->OnDelegateErrored += std::make_pair(this,&TestWeiboHelper::OnWeiboRespErrored);
weiboPtr->OnDelegateWillRelease += std::make_pair(this,&TestWeiboHelper::OnWeiboRespStopped);
}
TestWeiboHelper::~TestWeiboHelper()
{
weiboPtr->OnDelegateComplated -= std::make_pair(this,&TestWeiboHelper::OnWeiboRespComplated);
weiboPtr->OnDelegateErrored -= std::make_pair(this,&TestWeiboHelper::OnWeiboRespErrored);
weiboPtr->OnDelegateWillRelease -= std::make_pair(this,&TestWeiboHelper::OnWeiboRespStopped);
weiboPtr->shutdown();
}
void TestWeiboHelper::run()
{
weiboPtr->startup();
weiboPtr->setOption(WOPT_CONSUMER,APP_KEY,APP_SECRET);
std::string url("https://api.weibo.com/oauth2/authorize?client_id=");
url += APP_KEY;
url += "&redirect_uri=";
url += REDIRECT_URL;
url += "&response_type=code";
url += "&display=client";
std::cout<<"Please input code :"<<endl;
std::string code;
std::cin>>code;
weiboPtr->getMethod()->oauth2Code(code.c_str(),REDIRECT_URL,NULL);
std::cout<<"Please input access_token :"<<endl;
std::string _access_token;
std::cin>>_access_token;
weiboPtr->setOption(WOPT_ACCESS_TOKEN,_access_token.c_str());
//发送一条微博
weiboPtr->getMethod()->postStatusesUpdate("This is a test");
}
void TestWeiboHelper::OnWeiboRespComplated (unsigned int methodOption, const char* httpHeader,
ParsingObject* result, const UserTaskInfo* pTask)
{
std::cout<<"OnWeiboRespComplated :"<<methodOption<<endl;
OnResponseProcess(methodOption,result,0,0,true);
}
void TestWeiboHelper::OnWeiboRespErrored (unsigned int methodOption, const int errCode, const int subErrCode,
ParsingObject* result, const UserTaskInfo* pTask)
{
std::cout<<"OnWeiboRespErrored : "<<methodOption<<" "<<errCode<<"["<<subErrCode<<"]"<<endl;
OnResponseProcess(methodOption,result,errCode,subErrCode,false);
}
void TestWeiboHelper::OnWeiboRespStopped (unsigned int methodOption, const UserTaskInfo* pTask)
{
std::cout<<"OnWeiboRespStopped : "<<methodOption<<endl;
}
void TestWeiboHelper::OnResponseProcess(unsigned int optionId, ParsingObject* resultObj, const int errCode, const int errSubCode, bool isComplated)
{
if (isComplated)
{
if (resultObj && resultObj->isUseable())
{
switch(optionId)
{
case WBOPT_OAUTH2_ACCESS_TOKEN:
{
std::string originString = resultObj->getOriginString();
access_token = originString.substr(17,32);
weiboPtr->setOption(WOPT_ACCESS_TOKEN,access_token.c_str());
}
default :
break;
}
}
}
}
【 在 by2011210795 的大作中提到: 】
: 最近要采集新浪微博好友关系的拓扑结构,网上说API可以实现,现在正在看API,有没有大神曾经使用过微博API或者做过采集好友关系的呀?要是能指点一二就感激不尽啊!