Posting savescreen to FB - android

I need help to solve this problem: I want to post on FB a save screen from my app (I got save screen by using display.save function). Everything works fine on Android while on my iPad it crashes! Please find the function code below:
local function postonFB( event)
display.save( tab3fields, { filename="ticket.jpg", baseDir=system.DocumentsDirectory, isFullResolution=true, backgroundColor={0, 0, 0, 0} } )
local fbAppID = "4531113981XXXXX"
local function fbListener( event )
if event.phase == "login" then
local attachment = {
message="I am a champion!",
source= {baseDir=system.DocumentsDirectory, filename="ticket.jpg", type="image"}
}
facebook.request("me/photos", "POST", attachment)
native.showAlert("Facebook", "Submitted!")
end
end
-- photo uploading requires the "publish_actions" permission
facebook.login( fbAppID, fbListener, { "publish_actions" } )
end
Please help, I am getting crazy to understand what's wrong!
Thanks a lot. Ubaldo

here is my facebook sharing code:
baseDir = system.DocumentsDirectory
display.save( group , "screenshot.png", system.DocumentsDirectory )
local facebook = require "facebook"
local fbAppID = "898209XXXXXXXXX"
function onLoginSuccess()
attachment = {
message = "i got ".. score .. " blablabla",
source = { baseDir=system.DocumentsDirectory, filename="screenshot.png", type="image" }
}
facebook.request( "me/photos", "POST", attachment )
end
function fbListener( event )
if event.isError then
native.showAlert( "ERROR", event.response, { "OK" } )
else
if event.type == "session" and event.phase == "login" then
onLoginSuccess()
elseif event.type == "request" then
print("upload done")
end
end
end
facebook.login( fbAppID, fbListener, { "publish_stream", "publish_actions" } )
ps do you have this in you build.settings?
plugins =
{
["facebook"] =
{
publisherId = "com.coronalabs"
},
},

Related

How to get Instagram Following List using Instagram graph api

How to get the following list from the Instagram account using the access token
I tried everything but not work.
here some API link which I tried before but none of them work.
I tried this one https://www.instagram.com/urvish_._/?__a=1
also this one
I tried but nothing can help me.
You can get the following (or also follower) list using the code below. Steps:
Make sure you're logged in on instagram.com
Open the API link: https://www.instagram.com/urvish_._/?__a=1 (your target username here is urvish_._)
Open the browser console: normally Ctrl+Shift+J on Windows/Linux or ⌘+Option+J on Mac
Paste this code and press Enter:
const GRAPHQL_MAX_PER_PAGE = 50;
async function getList() {
let pageLimit = 200; // from my testing
let baseInfo = JSON.parse(document.getElementsByTagName('body')[0].innerText);
let userId = baseInfo.graphql.user.id;
let config = { user_edge: 'edge_follow', query_hash: 'd04b0a864b4b54837c0d870b0e77e076', total_count: baseInfo.graphql.user.edge_follow.count };
// for followers instead of followings:
// { user_edge: 'edge_followed_by', query_hash: 'c76146de99bb02f6415203be841dd25a', total_count: baseInfo.graphql.user.edge_followed_by.count }
let after = null, hasNext = true, thisList = [];
for (pageCount = 1; hasNext && (pageCount <= pageLimit); ++pageCount) {
try {
let response = await fetch(`https://www.instagram.com/graphql/query/?query_hash=${config.query_hash}&variables=` + encodeURIComponent(JSON.stringify({
id: userId, include_reel: true, fetch_mutual: true, first: GRAPHQL_MAX_PER_PAGE, after: after
})));
if (!response.ok) {
console.warn(`Failed at page number ${pageCount.toLocaleString()}. HTTP status ${response.status}: ${response.statusText}.`);
break;
}
try {
response = await response.json();
} catch (error) {
console.error(`You may need to verify your account. Stopping. Failed at page number ${pageCount.toLocaleString()}.`, error);
break;
}
hasNext = response.data.user[config.user_edge].page_info.has_next_page
after = response.data.user[config.user_edge].page_info.end_cursor
thisList = thisList.concat(response.data.user[config.user_edge].edges.map(({ node }) => {
return {
id: node.id,
username: node.username,
full_name: node.full_name,
profile_pic_url: node.profile_pic_url,
};
}));
} catch (error) {
console.warn(`Error at page number ${pageCount.toLocaleString()}:`, error);
}
console.log(`${thisList.length.toLocaleString()} of ${config.total_count.toLocaleString()} fetched so far`);
}
console.info(`${thisList.length.toLocaleString()} fetched.`);
console.log(thisList);
}
getList()
Browser console showing a fetched list after code execution
In the code I've set the page limit to 200 so you can get up to 10,000 of your followings.
PS: For a way to visualise your lists and get more details, you can try Instagram Lists, a tool I made.

Ionic reading data from SQLite during login in Android

Im facing a problem reading the already set data from previous login after user abruptly switches from my App into another or restarts the phone. The data I've set after successful login does get saved in the SQLite database.
.controller('LoginCtrl', function($scope, $ionicPopup, $state,$http,ServerEndPoint,localStorageService,$cordovaGeolocation,$ionicActionSheet,dataShare,$ionicPush,loading,$rootScope,$cordovaSQLite) {
$scope.data = {};
//Does not work
$scope.init = function()
{
$scope.load();
};
if(localStorageService.get("tradie_id") !== null && localStorageService.get("phone_no") !== null) {
$state.go('menu.map');
}
//This is called from login form submit button click
$scope.authenticateUser = function(loginForm){
//Authenticating user from the server, after successful login
//This one works
$scope.addInfo(res.data.user_id,res.data.first_name,res.data.phone_no,status);
$state.go('menu.map');
}
$scope.addInfo = function(user_id,first_name,phone_no,status){
var query = "INSERT INTO user_data(user_id,first_name,phone_no,status) VALUES(?,?,?,?)";
$cordovaSQLite.execute(db,query,[user_id,first_name,phone_no,status]);
$scope.load();
}
$scope.load = function(){
$scope.alldata = [];
$cordovaSQLite.execute(db,"SELECT * FROM user_data").then(function(result){
if(result.rows.length)
{
for(var i=0;i<result.rows.length;i++)
{
$scope.alldata.push(result.rows.item(i));
}
localStorageService.set("user_id", $scope.alldata[0].tradie_id);
localStorageService.set("first_name", $scope.alldata[0].first_name);
localStorageService.set("phone_no", $scope.alldata[0].phone_no);
}else
{
console.log("No data found");
}
},function(error){
console.log("error "+err);
})
}
})
Any suggestions or pointers to a sample source code is highly appreciated. I'm using ionic version 1.
I think you didn't create or open the db when app ready first:
var db = $cordovaSQLite.openDB({ name: "my.db" });

Sharing post using Facebook Graph API in Android

I'm trying to share post using Facebook APIs inside my application , i created an account on Facebook Developer and i put the app id inside the application , the login process is working fine and if i shared a post from the developer Facebook account , every thing is fine . But when i try to share using any other Facebook account i got nothing shared .
I'm using Facebook SDK 3.5 and below are the sharing code:
/**
* Post message with image
*
* #param imageURl
*/
public void postStatusMessage( byte [] imageURl ) {
if ( checkPermissions( Session.getActiveSession() ) ) {
final CustomProgressDialog progress = new CustomProgressDialog( FBActivity.this ) ;
progress.show() ;
// Filling the needed data for the share
Bundle parameters = new Bundle() ;
parameters.putString( "message" , shareText.getText().toString() ) ; // message
parameters.putString( "description" , name ) ;// description
parameters.putString( "link" , linkUrl ) ;// link if available
parameters.putByteArray( "picture" , imageURl ) ;// byte array for the image so it can be shared as image not as link
Request.Callback callback = new Request.Callback() {
public void onCompleted( Response response ) {
if ( response.getError() == null ) {
// Share post was done succesfully
Toast.makeText( FBActivity.this , getString( R.string.statusUpdateSucc ) , Toast.LENGTH_LONG ).show() ;
onlineActionID = ( String ) response.getGraphObject().getProperty( "id" ) ;
shareSuccesfuly = true ;
} else {
// Fail in share
Toast.makeText( FBActivity.this , "" + getString( R.string.statusUpdateFail ) , Toast.LENGTH_LONG ).show() ;
}
// Dismiss progress dialog
if ( progress.isShowing() )
progress.dismiss() ;
// if share was done sucessfully , navigate back to the previvos page
if ( shareSuccesfuly ) {
finish() ;
}// end if.
else {
finish() ;
}// end else().
}
} ;
// Request should have the me/photos tag so we can share photos in the user profile
Request request = new Request( Session.getActiveSession() , "me/photos" , parameters , HttpMethod.POST , callback ) ;
request.executeAsync() ;
} else {
requestPermissions() ;
}
}
The SDK you are using is very old, I strongly recommend you update to the latest release
You need to get the permissions needed approved by facebook, see this doc
Once done, you need to make your app live from the Status & Review tab
You shouldn't keep asking users for the publish permission, but instead describe why this is needed, see the guidelines here.

Corona SDK - email doesn't send

I'm trying to send an email using native.showPopup, but the email is never sent, below is the code:
function scene:createScene( event )
function sendMail()
local options =
{
to = "yourname#youremail.com",
subject = "Game Result",
isBodyHtml = true,
body = "<html><body>Play Time: <b>10</b> <br> Score: <b>1</b></body></html>"
}
native.showPopup("mail", options)
end
-- add some button to send mail
submitBtn = widget.newButton{
defaultFile="assets/submit.png",
over="assets/submit.png",
width=display.contentWidth/2, height=display.contentHeight/6,
onPress = sendMail
}
end
scene:addEventListener( "createScene", scene )
return scene
and this is the build.settings:
settings = {
android =
{
versionCode = "11",
usesPermissions =
{
"android.permission.INTERNET",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.ACCESS_COARSE_LOCATION",
}
},
}
I've tried in simulator and on my phone, but nothing is working. Can anyone help me?
i dont know why, but i just add some validation and now its work..
here the revision code i made:
function sendMail()
local options =
{
to = "yourname#youremail.com",
subject = "Game Result",
isBodyHtml = true,
body = "<html><body>Play Time: <b>10</b> <br> Score: <b>1</b></body></html>"
}
-- add some validation
-- and this is revision code
local mailSend = native.showPopup("mail", options)
if not mailSend then
native.showAlert( "Alert!", "Mail cannot be send.", { "OK" })
end
end
thx

Xmlhttprequest returns 401 on phonegap/android application

I want to access to the service web via my PhoneGap/android application with xmlhttprequest, but the code below returns "Status is 401".
var request = new XMLHttpRequest();
request.open("GET","http://www.mysite.fr/api/customers/2",true);
request.onreadystatechange = function() {
alert("Status is "+request.status);
if (request.status == 200 || request.status == 0){
response = request.responseXML.documentElement;
itemDescription = response.getElementsByTagName('lastname')[0].firstChild.data;
alert ( itemDescription );
}
}
request.send();
Can anyone help me explaining the error or offering me a solution?
if your website is created by prestashop, so to access the webservice using Xmlhttprequest, the request.open should be like this:
request.open("GET","http://www.mysite.fr/api/customes/2?PHP_AUTH_USER="+PHP_AUTH_USER+"&ws_key="+ws_key,true);
with: PHP_AUTH_USER="" and ws_ke=key_generated_by_the_webservice

Categories

Resources