Parse JSON with facebook sdk - android

I was wondering how to get the value of "name" for the following json text with facebook sdk. Assuming I have already got the access token. Any thoughts? Many thanks!
enter code here
{
"id": "100005065353669",
"music": {
"data": [
{
"category": "Musician/band",
"name": "Eason Chan",
"id": "105468519487919",
"created_time": "2013-06-05T20:33:26+0000"
}
],
"paging": {
"next": "https://graph.facebook.com/100005065353669/musiclimit=5000&offset=5000&__after_id=105468519487919"
}
}
}

Related

Integrating PayPal Checkout in an Android app

I am integrating Paypal checkout in an Android App using REST APIs provided by Paypal and my country is India so I am following this guide from PayPal.
How I did as per docs:
Get access-token (/v1/oauth2/token) for further api calls.
Use the Create Order API to create a payment (v2/checkout/orders)and in the response we will get approval url at where you need to redirect user to make the payment.
Now my question is how do I know if payment transaction was successful or not in mobile app because I am using WebView in my app to load approval url.
Order is created like this and I load href inside webview:
{
"id": "1KK44573EX7352015",
"status": "CREATED",
"links": [
{
"href": "https://www.sandbox.paypal.com/checkoutnowtoken=1KK44573EX7352015",
"rel": "approve",
"method": "GET"
}
]
}
I did this way:
As soon as Payment is successfully completed by customer the return_url gets called with query parameters : PayerID & token(orderID). At that time we can update user's payment status in our database (Amount is not deducted yet still because order is yet not approved or captured).
After that we can capture our order (Make sure invoice-id is not duplicate) otherwise status will be not completed.
If order is not approved on the time of capture we get this kind of error:
{
"name": "UNPROCESSABLE_ENTITY",
"details": [
{
"issue": "ORDER_NOT_APPROVED",
"description": "Payer has not yet approved the Order for payment. Please redirect the payer to the 'rel':'approve' url returned as part of the HATEOAS links within the Create Order call or provide a valid payment_source in the request."
}
],
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "47af43e..",
"links": [
{
"href": "https://developer.paypal.com/docs/api/orders/v2/#error-ORDER_NOT_APPROVED",
"rel": "information_link",
"method": "GET"
}
]
}
If there is duplicate invoice-id you will see error at the time of capture:
{
"name": "UNPROCESSABLE_ENTITY",
"details": [
{
"issue": "DUPLICATE_INVOICE_ID",
"description": "Duplicate Invoice ID detected. To avoid a potential duplicate transaction your account setting requires that Invoice Id be unique for each transaction."
}
],
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "86e0cc7f....",
"links": [
{
"href": "https://developer.paypal.com/docs/api/orders/v2/#error-DUPLICATE_INVOICE_ID",
"rel": "information_link",
"method": "GET"
}
]
}
If there is currency based issue:
{
"name": "UNPROCESSABLE_ENTITY",
"details": [
{
"location": "body",
"issue": "CURRENCY_NOT_SUPPORTED",
"description": "Currency code is not currently supported. Please refer https://developer.paypal.com/docs/integration/direct/rest/currency-codes/ for list of supported currency codes."
}
],
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "d666b5e5eb0c0",
"links": [
{
"href": "https://developer.paypal.com/docs/api/orders/v2/#error-CURRENCY_NOT_SUPPORTED",
"rel": "information_link",
"method": "GET"
}
]
}
If your order is successfully captured with status as COMPLETED:
{
"id": "8G0042477K865063U",
"status": "COMPLETED",
"purchase_units": [
{
"reference_id": "default",
"shipping": {
"name": {
"full_name": "John Doe"
},
"address": {
"address_line_1": "10, east street",
"address_line_2": "first building",
"admin_area_2": "Mumbai",
"admin_area_1": "Maharashtra",
"postal_code": "400029",
"country_code": "NZ"
}
},
"payments": {
"captures": [
{
"id": "4K670967VH2547504",
"status": "PENDING",
"status_details": {
"reason": "RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION"
},
"amount": {
"currency_code": "NZD",
"value": "170.00"
},
"final_capture": true,
"seller_protection": {
"status": "ELIGIBLE",
"dispute_categories": [
"ITEM_NOT_RECEIVED",
"UNAUTHORIZED_TRANSACTION"
]
},
"invoice_id": "INV-1234567888",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/payments/captures/4K670967VH2547504",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v2/payments/captures/4K670967VH2547504/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/8G0042477K865063U",
"rel": "up",
"method": "GET"
}
],
"create_time": "2020-10-31T13:35:58Z",
"update_time": "2020-10-31T13:35:58Z"
}
]
}
}
],
"payer": {
"name": {
"given_name": "Sumit",
"surname": "Shukla"
},
"email_address": "testg32#gmail.com",
"payer_id": "VW87TYSM2GMZ4",
"address": {
"address_line_1": "10, east street",
"admin_area_2": "Mumbai",
"admin_area_1": "Maharashtra",
"postal_code": "400029",
"country_code": "NZ"
}
},
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/8G0042477K865063U",
"rel": "self",
"method": "GET"
}
]
}
After that you can redirect user to thank you page and update mobile app screen based on database values.

Linkedin Signin Profile Picture URL in v2 API

I am getting Profile picture URN, can anyone please help me out to get profile picture URL from URN.
here is what we getting from linkedin r_liteprofile.
{
"lastName": {
"localized": {
"en_US": "lastname"
},
"preferredLocale": {
"country": "US",
"language": "en"
}
},
"firstName": {
"localized": {
"en_US": "firstname"
},
"preferredLocale": {
"country": "US",
"language": "en"
}
},
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:C5603AQF_Vo5V5fn5eg"
},
"id": "FFeEsrZu6r"
}
I am already tried below format to get Profile Picture from URN
https://api.linkedin.com/v2/me?projection=(FFeEsrZu6r,profilePicture(urn:li:digitalmediaAsset:C5603AQF_Vo5V5fn5eg),oauth2_access_token=AQVMHHg5ML1RXq1Et3t8qtFvIFXnviuJKaVpSZQ5IjV83hfUVn1UvIfHNNOqerVDZqXxj01w3Nn7D013Y7-oe5GT5rhltLAR55YnSaepQrxdvmbBZnfYD39r9iCnuazciSi8y8gPdZ0zmRmqgio5xlBCjkyoTKvGFCB6jAy-UA7CN9kpJr98BWGmtR4T8cIWc8h1OBzCJBwQC2DpHImN78a517uONveMt8oJeaF6pnHMZRyiyDyyj9VHv1PXP7s78rTIk4eR5Dq7GR5MPtyE-O9w0DgESNJ7Df5wjcLX4o0Zb8KKeu8UWOY6q_P91unZ9xo-mBXhATtsCghigclS98eGZS_8Xg)
I have got answer for my mistake
https://api.linkedin.com/v2/me?projection=(id,profilePicture(displayImage~:playableStreams))&oauth2_access_token=HERE PASS ACCESS TOKEN.

Using Graph API , how to retrieve Images of the comments and replies to the comment?

I am creating an Android App.The App have a feature that retrieve Facebook posts using Graph API.
My Problem
My Problem is , the received JSON lacks the following fields:
Url for the images attached with the comments
Replies to the comments
Only No. of likes available. No Reactions list
For posts containing more than one images , full_picture fields contains link to only one image. Where is the link for other images ?
I used the /me/posts to get the posts.
Why I can't get the above details ?
Steps taken
I searched Stackoverflow but The answers only mentioned how to get images and replies for individual commment(by using comment id) , but no reference how to get it alongs with the JSON received from "/me/posts". (So , this is not a duplicate!!!!)
My Queries
Why I can't get the above details ?
What is the way to get comment's Images , replies,url for all images of the Parent post and Posts reactions in bundle.(that is along with the JSON of "/me/posts" without running /comment request for each and every comment?
My Code
Code the executes Graph Query
login_button.setReadPermissions(Arrays.asList(
"public_profile", "email", "user_birthday", "user_friends","user_posts", "user_status")); // Setting permissions
Bundle params = new Bundle();
params.putString("fields", "message,created_time,id,full_picture,status_type,source,comments.summary(true),likes.summary(true)");
params.putString("limit", "100");
new GraphRequest( loginResult.getAccessToken(), "/me/posts", params, HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
try {
EditText postsText = (EditText) findViewById(R.id.postText);
String res = response.toString();
res = res.replaceAll("\\{Response:\\s*\\w*\\W*\\s*[0-9]*\\W*\\w*:", "");
res = res.replaceAll("\\,\\s*error:\\s*null\\W*\\s*","");
postsText.setText(res);
writeToFile(res,"response");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
).executeAsync();
}
#Override
public void onCancel() {
txtstatus.setText("Login canceled");
}
#Override
public void onError(FacebookException error) {
txtstatus.setText("Login failed"+error.getMessage());
}
});
JSON
{
"data": [
{
"message": "'A reader lives a thousand lives before he dies. The man who never reads lives only one.'\n- George RR Martin",
"created_time": "2018-01-28T12:17:54+0000",
"id": "113326729482474_113029916178822",
"full_picture": "https://scontent.xx.fbcdn.net/v/t1.0-9/26993527_113029839512163_7617357733573673432_n.jpg?oh=c617cf94e3cdd62320fde60e445f760e&oe=5B22BC72",
"status_type": "added_photos",
"likes": {
"data": [],
"summary": {
"total_count": 0,
"can_like": true,
"has_liked": true
}
},
"comments": {
"data": [
{
"created_time": "2018-01-28T12:23:04+0000",
"from": {
"name": "Ragesh D Antony",
"id": "1845099915531898"
},
"message": "Such a wonderful Quote ..",
"id": "113029916178822_113036856178128"
},
{
"created_time": "2018-01-28T13:59:22+0000",
"from": {
"name": "Vignesh Lakshmanen",
"id": "1558536637578045"
},
"message": "Superb",
"id": "113029916178822_113251916156622"
}
],
"paging": {
"cursors": {
"before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEV6TURNMk9EVTJNVGM0TVRJNE9qRTFNVGN4TkRJeE9EUT0ZD",
"after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEV6TWpVeE9URTJNVFUyTmpJeU9qRTFNVGN4TkRjNU5qST0ZD"
}
},
"summary": {
"order": "chronological",
"total_count": 2,
"can_comment": true
}
}
},
{
"message": "\"It's an insane world, but in it there's one sanity, the loyalty of old friends. Friends, we must believe in one another.\" \n\n- Ben Hur",
"created_time": "2018-01-28T12:14:27+0000",
"id": "113326729482474_113026646179149",
"status_type": "mobile_status_update",
"likes": {
"data": [
{
"id": "1845099915531898",
"name": "Ragesh D Antony"
},
{
"id": "1558536637578045",
"name": "Vignesh Lakshmanen"
}
],
"paging": {
"cursors": {
"before": "MTg0NTA5OTkxNTUzMTg5OAZDZD",
"after": "MTU1ODUzNjYzNzU3ODA0NQZDZD"
}
},
"summary": {
"total_count": 2,
"can_like": true,
"has_liked": false
}
},
"comments": {
"data": [
{
"created_time": "2018-01-28T12:24:40+0000",
"from": {
"name": "Ragesh D Antony",
"id": "1845099915531898"
},
"message": "I like Ben Hur very much",
"id": "113026646179149_113040629511084"
}
],
"paging": {
"cursors": {
"before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEV6TURRd05qSTVOVEV4TURnME9qRTFNVGN4TkRJeU9EQT0ZD",
"after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEV6TURRd05qSTVOVEV4TURnME9qRTFNVGN4TkRJeU9EQT0ZD"
}
},
"summary": {
"order": "chronological",
"total_count": 1,
"can_comment": true
}
}
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.11/113326729482474/posts?fields=message,created_time,id,full_picture,status_type,source,comments.summary%28true%29,likes.summary%28true%29&limit=100&format=json&since=1517141874&access_token=EAATh9tg5DMIBANl59BIPExJRzwZAhedH6PSsV2ZAO9FvzFiGqAW3HKafH9b7Bb0gSKnQMJktzUhX2DZCB29BezRUfI2HOumZAYp6FFYwOBJA1ZCdaE4ZCNLXB1ctUZBaKwbp8lXlZBwZBLLCG25CnGAckZClJXZA5omRDFtVvnJFTkJpqigUmy22QNGFmF4CgfC6sWEuVin7mAI9WZCkKkNVzSEeDGDoitt7xeVFiHXCetKOVoLZAl3qyfrYj&__paging_token=enc_AdC03uweQZCRZBN6tZCzhAQ50BZCKzx5koYtAZBRUmgY94TKcCrj6owvzXw9lpoL4iBKJUkW1ZAz4MoZAZBBaGSLZAHTHsKuEst7gtKaQrsQoiZBx8sO2QjQZDZD&__previous=1",
"next": "https://graph.facebook.com/v2.11/113326729482474/posts?fields=message,created_time,id,full_picture,status_type,source,comments.summary%28true%29,likes.summary%28true%29&limit=100&format=json&access_token=EAATh9tg5DMIBANl59BIPExJRzwZAhedH6PSsV2ZAO9FvzFiGqAW3HKafH9b7Bb0gSKnQMJktzUhX2DZCB29BezRUfI2HOumZAYp6FFYwOBJA1ZCdaE4ZCNLXB1ctUZBaKwbp8lXlZBwZBLLCG25CnGAckZClJXZA5omRDFtVvnJFTkJpqigUmy22QNGFmF4CgfC6sWEuVin7mAI9WZCkKkNVzSEeDGDoitt7xeVFiHXCetKOVoLZAl3qyfrYj&until=1517140875&__paging_token=enc_AdC1r6ZBwBybSmO16DuZCEWGDbdqTeiKCbTsa7h6WDenaZBgB40Xbc0flGcwYqiYPFiEf9wEvuBSoEvbfyl25J0JlbyfhKA1ZBufZC5ZAJMqLMg6bAXgZDZD"
}
}
Well, regarding "reaction list", this is available only for the Page owner (starting from 2018 Febraury).
Read the Graph API docs:
https://developers.facebook.com/docs/graph-api/reference/v2.12/post
"For Posts on a Page:
Any valid access token can read posts on a public Page, but responses will not include User information.
A Page access token can read all Posts posted to or posted by that Page, and responses will include User information."

Getting issue in get id from youtube API

I am trying to get Id from Youtube API in android app but unable to find
https://www.googleapis.com/youtube/v3/channels?part=id&forUsername={username}&key={YOUR_API_KEY}
But getting this response:
{
"kind": "youtube#channelListResponse",
"etag": "\"sNu6csVZt536JdlmpOxN9WQSd8U/ewwRz0VbTYpp2EGbOkvZ5M_1mbo\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": []
}
I have also tried with this
https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails&mine=true&key={YOUR_API_KEY}
But a response is below:
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "authorizationRequired",
"message": "The request uses the \u003ccode\u003emine\u003c/code\u003e parameter but is not properly authorized.",
"locationType": "parameter",
"location": "mine"
}
],
"code": 401,
"message": "The request uses the \u003ccode\u003emine\u003c/code\u003e parameter but is not properly authorized."
}
}
make sure you are logged-in with OAuth when performing these calls and if you're going to parse the JSON response to look for the id, it's found in items.id
Tried this with Channels.list Try-it and I got correct response:
/**
* API response
*/
{
"kind": "youtube#channelListResponse",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejnRI/X6OHzHqUUEu1okILXdfdfBbUxU\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejfdf/Qw3dXynuD_IdfB1LMKjSeiDI\"",
"id": "UCTjdfopNLdfd5yXVv93Ww"
}
]
}

Obtaining facebook cover photos

How I can get the cover photo of the albums of a user in my application?
Currently, I have a json like this:
"id": "00000",
"albums": {
"data": [
{
"id": "428076573767",
"from": {
"name": "Benjamin",
"id": "00000"
},
"name": "Profile Pictures",
"link": "https://www.facebook.com/album.php?fbid=00000&id=00000&aid=00000",
"cover_photo": "10151465301937683",
"privacy": "everyone",
"count": 57,
"type": "profile",
"created_time": "2010-09-05T08:42:19+0000",
"updated_time": "2013-04-27T23:53:11+0000",
"can_upload": false
},
}
How I can get the cover_photo by URL?
You can get cover photo by adding this into URL. No need to extract cover_photo from Json .
album['id']?>/picture?access_token=12345
// where album is JSON array and access_token is random here..
Try this. It will work.

Categories

Resources