Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
SumiSadiq
Posts: 148
Registered: ‎04-08-2013
My Device: Blackberry 10
My Carrier: Blackberry
Accepted Solution

FB post using Open graph API without SDK

In my app I want to post on FB wall.Iam using Graph API.AS there is no SDK I did the following steps:

1)Loaded Fb login page

2)captured Access tocken which comes along with the redirectUrl after I log in.

Now What I need is I want to call Open Graph API along with the access tocken ie,

 

"https://graph.facebook.com/me/og.likes?access_token="+ getAccessTocken.getAccessTocken(request.url)+"&method=POST&object=http://27.251.157.211:8080/balackberry.html"

 

And I should get the response as some  Qmap or something.So that based upon that response I can show the corresponding Alert to the user.What I should use here.(I read the doc about QnetworkAccess but no results was found Also i triedhttp://kunalmaemo.blogspot.kr/2012/01/posting-on-facebook-wall-from-qt.html this but it is explained in QT and I cant find any Answer from that too).Anyone plz help me out

Please use plain text.
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)
My Carrier: Mobile Vikings

Re: FB post using Open graph API without SDK

I suggest using the QNetworkAccessManager, it's really easy to do both GET and POST requests. If you have some code that is not working I would gladly take a look at it.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: FB post using Open graph API without SDK

i cannot find the link right now, but i think somebody posted about a sample last week on twitter.
check https://github.com/blackberry
i know there is an oAuth sample there, maybe more.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
msvishnumkl
Posts: 48
Registered: ‎05-02-2013
My Device: Z 10
My Carrier: airtel

Re: FB post using Open graph API without SDK

All best for you r project.

If u have sucessfully done with the Facebook post. I expect you to public the code.

plss help me with it.

i searching   for it  .

Please use plain text.
Developer
SumiSadiq
Posts: 148
Registered: ‎04-08-2013
My Device: Blackberry 10
My Carrier: Blackberry

Re: FB post using Open graph API without SDK

void FacebookHelper::postToWall(const QString& method, const QString& object)
   {
    QMap<QString,QString> data;
    data["access_token"] = mAccessToken;
    data["method"] = method;
    data["object"] = object;
    sendMessage(data);
}
 
void FacebookHelper::sendMessage( const QMap<QString,QString>& post)
{
    QString postData;
     foreach( QString key, post.keys()) {
        postData.append(key +"=" +post[key]+"&");
    }
   mCurrentRequest  =    mNetManager.post(QNetworkRequest(QUrl("https://graph.facebook.com/me/og.likes?")),postData.toAscii());
  connect(mCurrentRequest,SIGNAL(finished()),this,SLOT(messageResponse()));
}

void FacebookHelper::messageResponse()
{

    qDebug() << "error ="+ mCurrentRequest->error();
    qDebug() << "error string ="+ mCurrentRequest->errorString();
 
    if( mCurrentRequest->error() == QNetworkReply::NoError)
    {
         messageStatus( 0, mCurrentRequest->readAll() );
    }
  else
    {
         messageStatus( mCurrentRequest->error(), mCurrentRequest->errorString() );
    }
}

 Here is my code.I got the Access tocken from the redirect Url and I called the PostToWall function(upto there all works fine).

My problem is:

1)In messageResponse Function Iam getting that there is an error occured But Iam not getting what is the error ie,mcurrentREquest->error() and mCurrentRequest->errorString() are not returning anything.(I have also tried "get" method also instead of "post" in the above code but no change)

(While I load the url with the Access tocken which is to post text using Graph API (Url written in the code above) in a webView,An error Msg with code,error discription etc was shown in the webView.My hope was If Iam getting those error Msg as response while using QnetworkAccess Then I could seach for the error code and Accordingly I can show alert to the user.But here no error msg is given as response)

 

Plz help me out

 

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: FB post using Open graph API without SDK

maybe the error is only in the html code, i suggest that you call readAll in this case as well and check its contents.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
SumiSadiq
Posts: 148
Registered: ‎04-08-2013
My Device: Blackberry 10
My Carrier: Blackberry

Re: FB post using Open graph API without SDK

I tried With readall() but as I Qdebug it no data is returned.If Iam using 

 mCurrentRequest->error() then data returned is  protocol "" is unknown

Please use plain text.
Developer
SumiSadiq
Posts: 148
Registered: ‎04-08-2013
My Device: Blackberry 10
My Carrier: Blackberry

Re: FB post using Open graph API without SDK

There is no use while I tried with readAll.Help me plz.Iam stucked here
Please use plain text.
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)
My Carrier: Mobile Vikings

Re: FB post using Open graph API without SDK

Hi SumiSadiq,

 

I received your PM, but it's a bit hectic at work so I'll come back later for a good look at your problem. First of all a suggestion: don't connect your signal on every request. 

 

I suggest forming your code like my code or pasting your entire code regarding the network (I don't see the QNetworkAccessManager being constructed anywhere for example).

 

My sample code (based on ToodleTen's code):

 

void DeletedTaskAPI::getDeletedTasks(int modAfter)
{
	QUrl url("http://api.toodledo.com/2/tasks/deleted.php");
	//Prepare parameters
	QUrl params;
	params.addQueryItem("key", Information::getSessionToken());
	params.addQueryItem("after", QString::number(modAfter));
	params.addQueryItem("f", "xml");
	QByteArray data;
	data = params.encodedQuery();
	//Prepare request
	QNetworkRequest request;
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
	request.setUrl(url);
	//Execute request
	networkManager->post(request, data);
}

void DeletedTaskAPI::networkFinishedSlot(QNetworkReply* reply)
{
	if(reply->error() == QNetworkReply::NoError)
	{
		QString xmlReply = QString::fromUtf8(reply->readAll());
		qDebug() << xmlReply;
		//Process data here
	}
	else
	{
		NetworkErrorHandler::getInstance()->processNetworkError(reply->error());
	}
}

/**
 * Constructor & Destructor
 */
DeletedTaskAPI::DeletedTaskAPI()
{
	networkManager = new QNetworkAccessManager();
	connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkFinishedSlot(QNetworkReply*)));
}

DeletedTaskAPI::~DeletedTaskAPI()
{
	delete networkManager;
}

 NetworkErrorHandler is my custom class that reads the error codes from the used API and presents them in a nice dialog to the user.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
Developer
SumiSadiq
Posts: 148
Registered: ‎04-08-2013
My Device: Blackberry 10
My Carrier: Blackberry

Re: FB post using Open graph API without SDK

Thanks a lot my friend Zezke.That works for me.I get the error message correctly.The problem was with the connection with the signal.I gave the connection in the constructor and also create the QnetworkAccessObject in the constructor and that works fine.
Please use plain text.