37 |
39 |
38 #ifdef SMF_XMLPARSING |
40 #ifdef SMF_XMLPARSING |
39 SmfContact contact; |
41 SmfContact contact; |
40 #endif |
42 #endif |
41 |
43 |
|
44 // Todo:- Macro added for limiting items fetched to recent 5 |
|
45 // Remove after demo |
|
46 #define SETLIMITOFFIVEFORSMFDEMO 1 |
42 |
47 |
43 /** |
48 /** |
44 * Destructor |
49 * Destructor |
45 */ |
50 */ |
46 FBContactFetcherPlugin::~FBContactFetcherPlugin( ) |
51 FBContactFetcherPlugin::~FBContactFetcherPlugin( ) |
47 { |
52 { |
48 if(m_provider) |
53 if(m_provider) |
49 delete m_provider; |
54 delete m_provider; |
50 } |
55 } |
|
56 |
|
57 /** |
|
58 * Method to interpret the key sets obtained from credential manager |
|
59 * @param aApiKey [out] The api key |
|
60 * @param aApiSecret [out] The api secret |
|
61 * @param aSessionKey [out] The session key |
|
62 * @param aSessionSecret [out] The session secret |
|
63 * @param aAppId [out] The application ID |
|
64 */ |
|
65 void FBContactFetcherPlugin::fetchKeys( QString &aApiKey, |
|
66 QString &aApiSecret, |
|
67 QString &aSessionKey, |
|
68 QString &aSessionSecret ) |
|
69 { |
|
70 qDebug()<<"Inside FBContactFetcherPlugin::fetchKeys()"; |
|
71 |
|
72 qDebug()<<"Reg Token = "<<m_provider->m_smfRegToken; |
|
73 qDebug()<<"Expiry Date as int = "<<m_provider->m_validity.toTime_t(); |
|
74 |
|
75 SmfAuthParams keys; |
|
76 SmfPluginUtil util; |
|
77 util.getAuthKeys(keys, m_provider->m_smfRegToken, |
|
78 m_provider->m_validity, m_provider->m_pluginId); |
|
79 |
|
80 qDebug()<<"Number of key-value pairs = "<<keys.count(); |
|
81 |
|
82 QByteArray keyName; |
|
83 keyName.append("ApiKey"); |
|
84 aApiKey.append(keys.value(keyName)); |
|
85 |
|
86 keyName.clear(); |
|
87 keyName.append("ApiSecret"); |
|
88 aApiSecret.append(keys.value(keyName)); |
|
89 |
|
90 keyName.clear(); |
|
91 keyName.append("SessionKey"); |
|
92 aSessionKey.append(keys.value(keyName)); |
|
93 |
|
94 keyName.clear(); |
|
95 keyName.append("SessionSecret"); |
|
96 aSessionSecret.append(keys.value(keyName)); |
|
97 |
|
98 qDebug()<<"Api Key = "<<aApiKey; |
|
99 qDebug()<<"Api Secret = "<<aApiSecret; |
|
100 qDebug()<<"session Key = "<<aSessionKey; |
|
101 qDebug()<<"session Secret = "<<aSessionSecret; |
|
102 } |
|
103 |
51 |
104 |
52 /** |
105 /** |
53 * Method to get the list of friends |
106 * Method to get the list of friends |
54 * @param aRequest [out] The request data to be sent to network |
107 * @param aRequest [out] The request data to be sent to network |
55 * @param aPageNum The page to be extracted |
108 * @param aPageNum The page to be extracted |
91 return error; |
143 return error; |
92 } |
144 } |
93 |
145 |
94 qDebug()<<"Valid arguments"; |
146 qDebug()<<"Valid arguments"; |
95 |
147 |
96 #if 1 |
148 // Get the key sets from SMF Plugin Utility class. |
97 // Reading the keys, CSM Stubbed - START |
149 QString apiKey; |
98 QFile file("c:\\data\\FacebookKeys.txt"); |
150 QString apiSecret; |
99 if (!file.open(QIODevice::ReadOnly)) |
151 QString sessionKey; |
100 { |
152 QString sessionSecret; |
101 qDebug()<<"File to read the keys could not be opened"; |
153 fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret); |
102 return SmfPluginErrUserNotLoggedIn; |
|
103 } |
|
104 |
|
105 qDebug()<<"Key file read, going to parse the key values from file"; |
|
106 |
|
107 QByteArray arr = file.readAll(); |
|
108 QList<QByteArray> list = arr.split('\n'); |
|
109 file.close(); |
|
110 |
|
111 QString apiKey(list[0]); |
|
112 QString apiSecret(list[1]); |
|
113 QString sessionKey(list[2]); |
|
114 QString sessionSecret(list[3]); |
|
115 |
|
116 qDebug()<<"Api Key = "<<apiKey; |
|
117 qDebug()<<"Api Secret = "<<apiSecret; |
|
118 qDebug()<<"session Key = "<<sessionKey; |
|
119 qDebug()<<"session Secret = "<<sessionSecret; |
|
120 // Reading the keys, CSM Stubbed - END |
|
121 #endif |
|
122 |
154 |
123 // Get the current date and time and convert it to seconds as a string |
155 // Get the current date and time and convert it to seconds as a string |
124 QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10); |
156 QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10); |
125 |
157 |
126 // Create the API signature string |
158 // Create the API signature string |
188 Q_UNUSED(aItemsPerPage) |
220 Q_UNUSED(aItemsPerPage) |
189 qDebug()<<"Inside FBContactFetcherPlugin::getFriendsDetails()"; |
221 qDebug()<<"Inside FBContactFetcherPlugin::getFriendsDetails()"; |
190 |
222 |
191 SmfPluginError error = SmfPluginErrUserNotLoggedIn; |
223 SmfPluginError error = SmfPluginErrUserNotLoggedIn; |
192 |
224 |
193 #if 1 |
225 // Get the key sets from SMF Plugin Utility class. |
194 // Reading the keys, CSM Stubbed - START |
226 QString apiKey; |
195 QFile file("c:\\data\\FacebookKeys.txt"); |
227 QString apiSecret; |
196 if (!file.open(QIODevice::ReadOnly)) |
228 QString sessionKey; |
197 { |
229 QString sessionSecret; |
198 qDebug()<<"File to read the keys could not be opened"; |
230 fetchKeys(apiKey, apiSecret, sessionKey, sessionSecret); |
199 return error; |
|
200 } |
|
201 |
|
202 qDebug()<<"Key file read, going to parse the key values from file"; |
|
203 |
|
204 QByteArray arr = file.readAll(); |
|
205 QList<QByteArray> list = arr.split('\n'); |
|
206 file.close(); |
|
207 |
|
208 QString apiKey(list[0]); |
|
209 QString apiSecret(list[1]); |
|
210 QString sessionKey(list[2]); |
|
211 QString sessionSecret(list[3]); |
|
212 |
|
213 qDebug()<<"Api Key = "<<apiKey; |
|
214 qDebug()<<"Api Secret = "<<apiSecret; |
|
215 qDebug()<<"session Key = "<<sessionKey; |
|
216 qDebug()<<"session Secret = "<<sessionSecret; |
|
217 // Reading the keys, CSM Stubbed - END |
|
218 #endif |
|
219 |
231 |
220 // Get the current date and time and convert it to sec as a string |
232 // Get the current date and time and convert it to sec as a string |
221 QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10); |
233 QString call_id = QString::number(QDateTime::currentDateTime().toTime_t(), 10); |
222 |
234 |
223 // Create the API signature string |
235 // Create the API signature string |
224 QString baseString; |
236 QString baseString; |
225 baseString.append("api_key="+apiKey); |
237 baseString.append("api_key="+apiKey); |
226 baseString.append("call_id="+call_id); |
238 baseString.append("call_id="+call_id); |
227 baseString.append("fields=uid,name,pic,pic_square"); |
239 baseString.append("fields=uid,name,pic,pic_square,status"); |
228 #ifdef SMF_XMLPARSING |
240 #ifdef SMF_XMLPARSING |
229 baseString.append("format=XML"); |
241 baseString.append("format=XML"); |
230 #else |
242 #else |
231 baseString.append("format=JSON"); |
243 baseString.append("format=JSON"); |
232 #endif |
244 #endif |
233 baseString.append("method=users.getInfo"); |
245 baseString.append("method=users.getInfo"); |
234 baseString.append("session_key="+sessionKey); |
246 baseString.append("session_key="+sessionKey); |
235 baseString.append("ss=1"); |
247 baseString.append("ss=1"); |
|
248 |
|
249 #ifdef SETLIMITOFFIVEFORSMFDEMO // limiting to fetch only first 5 contact details |
|
250 |
|
251 QStringList firstFiveUids = uids.split(','); |
|
252 uids.clear(); |
|
253 int i = 0; |
|
254 while(i < 5) |
|
255 { |
|
256 uids.append(firstFiveUids.at(i)); |
|
257 uids.append(","); |
|
258 i++; |
|
259 } |
|
260 if(firstFiveUids.count()>5) |
|
261 uids.chop(1); |
|
262 qDebug()<<"Limited to 5 uid string = "<<uids; |
|
263 #endif |
|
264 |
236 baseString.append("uids="+uids); |
265 baseString.append("uids="+uids); |
237 baseString.append("v=1.0"); |
266 baseString.append("v=1.0"); |
238 baseString.append(sessionSecret); |
267 baseString.append(sessionSecret); |
239 |
268 |
240 // Create the url |
269 // Create the url |
241 QUrl url("http://api.facebook.com/restserver.php?"); |
270 QUrl url("http://api.facebook.com/restserver.php?"); |
242 url.addQueryItem("api_key", apiKey); |
271 url.addQueryItem("api_key", apiKey); |
243 url.addQueryItem("call_id", call_id); |
272 url.addQueryItem("call_id", call_id); |
244 url.addQueryItem("fields", "uid,name,pic,pic_square"); |
273 url.addQueryItem("fields", "uid,name,pic,pic_square,status"); |
245 #ifdef SMF_XMLPARSING |
274 #ifdef SMF_XMLPARSING |
246 url.addQueryItem("format", "XML"); |
275 url.addQueryItem("format", "XML"); |
247 #else |
276 #else |
248 url.addQueryItem("format", "JSON"); |
277 url.addQueryItem("format", "JSON"); |
249 #endif |
278 #endif |
677 contactname.setLastName(map2["name"].toString()); |
718 contactname.setLastName(map2["name"].toString()); |
678 QVariant nameVar = QVariant::fromValue(contactname); |
719 QVariant nameVar = QVariant::fromValue(contactname); |
679 contact.setValue("Name",nameVar); |
720 contact.setValue("Name",nameVar); |
680 |
721 |
681 QContactAvatar avatar; |
722 QContactAvatar avatar; |
682 QUrl url(map2["pic_square"].toString()); |
723 QUrl url; |
|
724 if(0 != map2["pic_square"].toString().size()) |
|
725 url = map2["pic_square"].toString(); |
|
726 else |
|
727 url = QString("http://static.ak.fbcdn.net/rsrc.php/z5HB7/hash/ecyu2wwn.gif"); |
683 avatar.setImageUrl(url); |
728 avatar.setImageUrl(url); |
684 QVariant avatarVar = QVariant::fromValue(avatar); |
729 QVariant avatarVar = QVariant::fromValue(avatar); |
685 contact.setValue("Avatar", avatarVar); |
730 contact.setValue("Avatar", avatarVar); |
686 |
731 |
687 QContactGuid guid; |
732 QContactGuid guid; |
688 guid.setGuid(map2["uid"].toString()); |
733 guid.setGuid(map2["uid"].toString()); |
689 QVariant guidVar = QVariant::fromValue(guid); |
734 QVariant guidVar = QVariant::fromValue(guid); |
690 contact.setValue("Guid", guidVar); |
735 contact.setValue("Guid", guidVar); |
|
736 |
|
737 QContactPresence presence; |
|
738 presence.setCustomMessage(map2["status"].toString()); |
|
739 QVariant presVar = QVariant::fromValue(presence); |
|
740 contact.setValue("Presence", presVar); |
691 |
741 |
692 |
742 |
693 #if 0 // tesing SmfContact serialization |
743 #if 0 // tesing SmfContact serialization |
694 QContactAddress address; |
744 QContactAddress address; |
695 address.setCountry("sampleCountry"); |
745 address.setCountry("sampleCountry"); |