facebook sdk 7.2 unity 5.2 profile picture pulls though in the editor but not on the facebook canvus? - facebook

I have 2 problems currently
Im using unity 5.2.0 and the Facebook unity sdk 7.2
My unity is set to PC build (I will explain why just now)
I have been following the grey zoned tutorials and adapting them where needed for the new SDK. In my unity editor I currently have a place for my profile pic, the username, share and invite buttons along with the Facebook login button. When I run the project, it runs through everything perfectly. It gets the profile picture and the username and puts them where they need to be, the share and invite buttons post in the log that they are working so that's fine.
My first problem is:
When I put my editor in web player build, I always get this error when i try to log in. Any advice on fixing this part?
ArgumentException: Cannot overwrite header: User-Agent
UnityEngine.WWW.CheckSecurityOnHeaders (System.String[] headers) (at
C:/buildslave/unity/build/Runtime/Export/WWW.cs:71)
UnityEngine.WWW..ctor (System.String url, System.Byte[] postData,
System.Collections.Generic.Dictionary`2 headers) (at
C:/buildslave/unity/build/artifacts/generated/common/runtime/UtilsBindings.gen.cs:125)
Facebook.Unity.AsyncRequestString+c__Iterator1.MoveNext () (at
Assets/Facebook/Scripts/Utils/AsyncRequestString.cs:100)
My second problem is:
I build my project (web player build) and upload it to my hosted server, then when I hop on Firefox or Internet Explorer and go to my app on the Facebook canvas it loads up, but the profile pic and username do not appear. The sharing and invites work however. Its only the pic and name that do not pull through.
I'm going to put all my code in so that you can see exactly what I have done.
Sorry I'm very new to coding so it probably looks terrible.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;
using UnityEngine.UI;
using System;
public class FBholder : MonoBehaviour
{
public GameObject UIFBIsLoggedIn;
public GameObject UIFBIsNotLoggedIn;
public GameObject UIFBAvatar;
public GameObject UIFBUserName;
public GameObject ErrorText;
public Text errorText;
private Dictionary<string, string> profile = null;
void Awake()
{
FB.Init (SetInit, OnHideUnity);
}
private void SetInit()
{
errorText = ErrorText.GetComponent<Text>();
Debug.Log ("FB Init done.");
//LOG: Error Text
errorText.text = "FB Init done.";
Debug.LogWarning("LOG "+ errorText.text);
if (FB.IsLoggedIn)
{
DealWithFBMenus(true);
Debug.Log ("FB Logged In.");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "FB Logged In.";
Debug.LogWarning("LOG "+ errorText.text);
}else{
DealWithFBMenus(false);
FindTheStupidErrorLog();
errorText.text = "FB Not Logged In.";
Debug.LogWarning("LOG "+ errorText.text);
}
}
private void OnHideUnity(bool isGameShown)
{
if(!isGameShown)
{
Time.timeScale = 0;
}else{
Time.timeScale = 1;
}
}
public void FBlogin ()
{
var perms = new List<string>(){"public_profile", "email",};
FB.LogInWithReadPermissions(perms, AuthCallback);
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "FB Logged In.";
Debug.LogWarning("LOG "+ errorText.text);
}
private void AuthCallback (ILoginResult result)
{
if (FB.IsLoggedIn) {
DealWithFBMenus(true);
// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log(aToken.UserId);
// Print current access token's granted permissions
foreach (string perm in aToken.Permissions) {
Debug.Log(perm);
}
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "AuthCallback if";
Debug.LogWarning("LOG "+ errorText.text);
} else {
DealWithFBMenus(false);
Debug.Log("User cancelled login");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "AuthCallback else";
Debug.LogWarning("LOG "+ errorText.text);
}
}
void DealWithFBMenus(bool isLoggedIn)
{
if(isLoggedIn)
{
UIFBIsLoggedIn.SetActive (true);
UIFBIsNotLoggedIn.SetActive (false);
FB.API (Util.GetPictureURL("me", 128, 128), HttpMethod.GET, DealWithProfilePicture);
FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "running deal with menu If";
Debug.LogWarning("LOG "+ errorText.text);
}else{
UIFBIsLoggedIn.SetActive (false);
UIFBIsNotLoggedIn.SetActive (true);
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "running deal with menu else";
Debug.LogWarning("LOG "+ errorText.text);
}
}
void DealWithProfilePicture (IGraphResult result)
{
if(result.Error != null)
{
Debug.Log ("Problem getting Pic");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "Profile Pic Error";
Debug.LogWarning("LOG "+ errorText.text);
FB.API (Util.GetPictureURL("me", 128, 128), HttpMethod.GET, DealWithProfilePicture);
return;
}
Image UserAvatar = UIFBAvatar.GetComponent<Image>();
UserAvatar.sprite = Sprite.Create (result.Texture, new Rect(0,0,128,128), new Vector2(0,0));
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "Profile Pic loaded";
Debug.LogWarning("LOG "+ errorText.text);
}
void DealWithUserName (IGraphResult result)
{
if(result.Error != null)
{
Debug.Log ("Problem getting Pic");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "UserName didnt loaded";
Debug.LogWarning("LOG "+ errorText.text);
FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
return;
}
profile = Util.DeserializeJSONProfile(result.Text);
Text UserMsg = UIFBUserName.GetComponent<Text>();
UserMsg.text = "Hello, " + profile["first_name"];
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "UserName loaded";
Debug.LogWarning("LOG "+ errorText.text);
}
public void ShareWithFriends()
{
if (!FB.IsLoggedIn)
{
FBlogin();
Debug.Log ("not logged in to share");
}else {
Uri contentUri = new Uri("http://apps.facebook.com/" +FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? AccessToken.CurrentAccessToken.UserId : "guest"));
FB.ShareLink(
contentURL: contentUri,
contentTitle: "Me Testing the FB SDK",
contentDescription: "I wonder where this shows?",
photoURL: new Uri("https://dragondigital.co.za/fb_7.1_test/mascotOne.png"),
callback: ShareCallback
);
}
}
private void ShareCallback (IShareResult result)
{
if (result.Cancelled || !String.IsNullOrEmpty(result.Error)) {
Debug.Log("ShareLink Error: "+result.Error);
} else if (!String.IsNullOrEmpty(result.PostId)) {
// Print post identifier of the shared content
Debug.Log(result.PostId);
} else {
// Share succeeded without postID
Debug.Log("ShareLink success!");
}
}
public void InviteFriends()
{
FB.AppRequest(
message: "This is the Invite Message",
title: "This is the Invite Title."
);
print ("Invite prob worked");
//LOG: Error Text
FindTheStupidErrorLog();
errorText.text = "Invite prob worked";
}
public void FindTheStupidErrorLog()
{
if(errorText == null)
{
errorText = ErrorText.GetComponent<Text>();
}
}
}
Yes i know there is ALOT of redundant error logging but that will be taken out later :)
Any help you guys can give will be much appreciated :)

Related

POST requests to Flask from Unity result in `null` values

After getting this demo server working I am able return GET requests from it to Unity, but when I would try to send data from Unity to the local server using POST requests it would only show null values added into the server. This is the code I was using in Unity:
IEnumerator Upload()
{
WWWForm form = new WWWForm();
form.AddField("charge","+4/3");
form.AddField("name", "doubletop");
using (UnityWebRequest www = UnityWebRequest.Post("http://localhost:5000/quarks/", form))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Form upload complete!");
}
}
}
I would get "Form upload complete!" in the console, and GET requests would work, but those null values kept coming.
I modified my Upload() method to the PostRequest() in this example, and now it works!
Here's the full code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class HTTP : MonoBehaviour
{
void Start()
{
// A correct website page.
StartCoroutine(GetRequest("localhost:5000/quarks"));
PostData();
StartCoroutine(GetRequest("localhost:5000/quarks"));
// A non-existing page.
//StartCoroutine(GetRequest("https://error.html"));
}
IEnumerator GetRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
string[] pages = uri.Split('/');
int page = pages.Length - 1;
if (webRequest.isNetworkError)
{
Debug.Log(pages[page] + ": Error: " + webRequest.error);
}
else
{
Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
}
}
}
[Serializable]
public class Quark
{
public string name;
public string charge;
}
public void PostData()
{
Quark gamer = new Quark();
gamer.name = "doublebottom";
gamer.charge = "4/3";
string json = JsonUtility.ToJson(gamer);
StartCoroutine(PostRequest("http://localhost:5000/quarks", json));
}
IEnumerator PostRequest(string url, string json)
{
var uwr = new UnityWebRequest(url, "POST");
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json);
uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend);
uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
uwr.SetRequestHeader("Content-Type", "application/json");
//Send the request then wait here until it returns
yield return uwr.SendWebRequest();
if (uwr.isNetworkError)
{
Debug.Log("Error While Sending: " + uwr.error);
}
else
{
Debug.Log("Received: " + uwr.downloadHandler.text);
}
}
}

facebook login and share dialog not shown in android mobile in unity

I'm using facebook sdk 7.4 and unity 5.2.2f1 and I want to login into facebook profile and share the game using FB.FeedShare function in android phone. The login works in editor, but not in android phone. when login button is pressed, a dialog window is getting load but it disappears quickly. The share functionality has the same problem.
I'm stucked in this problem for 2 weeks, and I don't know what to do! I'll be so gratefull if anybody can solve it..
public void initFB() {
if (!FB.IsInitialized) {
FB.Init (setInit, onUnityHide);
} else {
isLoggedIn = FB.IsLoggedIn;
}
}
public void setInit() {
if (FB.IsLoggedIn) {
Debug.Log ("u r logged in!");
getProfile();
} else {
Debug.Log ("u r not logged in!");
}
isLoggedIn = FB.IsLoggedIn;
}
private void onUnityHide(bool isShown) {
if (!isShown) {
Time.timeScale = 0;
} else {
Time.timeScale = 1;
}
}
public void FBLogin() {
List<string> perms = new List<string> ();
perms.Add ("public_profile");
FB.LogInWithReadPermissions (perms, authCallBack);
}
public void authCallBack(IResult result) {
if (result.Error != null) {
Debug.Log (result.Error.ToString ());
} else {
if (FB.IsLoggedIn) {
FacebookManager.Instance.isLoggedIn = true;
FacebookManager.Instance.getProfile();
Debug.Log ("you are logged in!");
} else {
Debug.Log ("you are not logged in!");
}
setMenu(FB.IsLoggedIn);
}
}
public void share() {
FB.FeedShare (
string.Empty,
null,
"Hi Title!",
"Hi Caption!",
"Hi Description!",
new System.Uri("http://s3.img7.ir/hPyQA.jpg"),
string.Empty,
shareCall
);
}
public void shareCall(IResult result) {
if (result.Cancelled) {
Debug.Log ("share cancelled!");
} else if (!string.IsNullOrEmpty (result.Error)) {
Debug.Log ("error on share!");
} else if (!string.IsNullOrEmpty (result.RawResult)){
Debug.Log ("success on share!");
}
}

Getting Text from IResult Facebook SDK, 7.2.0

I am trying to get the player's username and then display it.
Recently, there was a breaking changes; IResult replacement for FBResult.
I was able to return a texture from the IGraphResult instead of FBResult, to display the profile picture, so I expect that the Text would be available as well but no.
So my issue is, where can I return the Text from?
Do I have to add anything to the IGraphResult?
Here is the code,
void DealWithUserName(FBResult result)
{
if(result.Error != null)
{
Debug.Log ("Problems with getting profile picture");
FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
return;
}
profile = Util.DeserializeJSONProfile(result.Text);
Text UserMsg = UIFBUsername.GetComponent<Text>();
UserMsg.text = "Hello, " + profile["first_name"];
}
Edited:
Okay, I did it.
It seems that I can also get the username from the IGraphResult.
So, I changed the FBResult to IGraphResult.
I changed result.Text to result.RawResult.
Here is the code, for anyone who needs it.
void DealWithUserName(IGraphResult result)
{
if(result.Error != null)
{
Debug.Log ("Problems with getting profile picture");
FB.API ("/me?fields=id,first_name", HttpMethod.GET, DealWithUserName);
return;
}
profile = Util.DeserializeJSONProfile(result.RawResult);
Text UserMsg = UIFBUsername.GetComponent<Text>();
UserMsg.text = "Hello, " + profile["first_name"];
}
Let's try it
private void DealWithUserName(IGraphResult result){
if (result.ResultDictionary != null) {
foreach (string key in result.ResultDictionary.Keys) {
Debug.Log(key + " : " + result.ResultDictionary[key].ToString());
// first_name : Chris
// id : 12345678901234567
}
}
Text UserName = UIUserName.GetComponent<Text>();
UserName.text = "Hello, "+ result.ResultDictionary["name"].ToString();
}

google cloud print from android without dialog

Can someone tell me if it is possible to silently print using google cloud print from an android device?
The goal is that my app grabs a file from a URL or from the SD card and then sends it to a specific printer - all without interaction from anyone looking at the screen or touching anything. It will actually be triggered by a barcode scan on a blue tooth connected device.
Thanks
Well, it is possible but I don't know why there's not too much information about it in the documentation...
The tricky part is connecting to the google cloud print API using only the android device (with no third party servers as the documentation explains here: https://developers.google.com/cloud-print/docs/appDevGuide ), so that's what I'm going to explain.
First, you have to include in your app the Google sign-in API, I recommend firebase API https://firebase.google.com/docs/auth/android/google-signin
Then you have to go to your Google API console: https://console.developers.google.com in the menu, go to Credentials scroll to OAuth 2.0 client IDs select Web client (auto created by Google Service) and save into your project the Client ID and Client secret keys... In my project, I saved them as "gg_client_web_id" and "gg_client_web_secret" as you will see below in the code.
Next, I'm going to paste all the code and then I'll explain it:
public class MainActivity extends AppCompatActivity
implements GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private static final int REQUEST_SINGIN = 1;
private TextView txt;
public static final String TAG = "mysupertag";
public static final String URLBASE = "https://www.google.com/cloudprint/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView) findViewById(R.id.txt);
mAuth = FirebaseAuth.getInstance();
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.gg_client_web_id))
.requestEmail()
.requestServerAuthCode(getString(R.string.gg_client_web_id))
.requestScopes(new Scope("https://www.googleapis.com/auth/cloudprint"))
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
signIn();
}
});
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// ...
}
};
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Log.d(TAG, "error connecting: " + connectionResult.getErrorMessage());
Toast.makeText(this, "error CONN", Toast.LENGTH_LONG).show();
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == REQUEST_SINGIN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
// Google Sign In failed, update UI appropriately
// ...
Toast.makeText(this, "error ", Toast.LENGTH_LONG).show();
}
}
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, REQUEST_SINGIN);
}
#Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
FirebaseUser user = task.getResult().getUser();
txt.setText(user.getDisplayName() + "\n" + user.getEmail());//todo
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
getAccess(acct.getServerAuthCode());
}
});
}
private void getPrinters(String token) {
Log.d(TAG, "TOKEN: " + token);
String url = URLBASE + "search";
Ion.with(this)
.load("GET", url)
.addHeader("Authorization", "Bearer " + token)
.asString()
.withResponse()
.setCallback(new FutureCallback<Response<String>>() {
#Override
public void onCompleted(Exception e, Response<String> result) {
Log.d(TAG, "finished " + result.getHeaders().code() + ": " +
result.getResult());
if (e == null) {
Log.d(TAG, "nice");
} else {
Log.d(TAG, "error");
}
}
});
}
private void getAccess(String code) {
String url = "https://www.googleapis.com/oauth2/v4/token";
Ion.with(this)
.load("POST", url)
.setBodyParameter("client_id", getString(R.string.gg_client_web_id))
.setBodyParameter("client_secret", getString(R.string.gg_client_web_secret))
.setBodyParameter("code", code)
.setBodyParameter("grant_type", "authorization_code")
.asString()
.withResponse()
.setCallback(new FutureCallback<Response<String>>() {
#Override
public void onCompleted(Exception e, Response<String> result) {
Log.d(TAG, "result: " + result.getResult());
if (e == null) {
try {
JSONObject json = new JSONObject(result.getResult());
getPrinters(json.getString("access_token"));
} catch (JSONException e1) {
e1.printStackTrace();
}
} else {
Log.d(TAG, "error");
}
}
});
}}
As you can see, in the onCreate the important part is creating the GoogleSignInOptions WITH the google cloud print scope AND calling the requestIdToken/requestServerAuthCode methods.
Then in the firebaseAuthWithGoogle method call the getAccess method in order to get the OAuth access token, for making all requests I'm using Ion library: https://github.com/koush/ion
Next with the access_token you can now do requests to the google cloud print API, in this case I call the getPrinters method, in this method I call the "search" method (from google cloud print API) to get all the printers associated to the google account that has signed in.. (to associate a printer to a google account visit this: https://support.google.com/cloudprint/answer/1686197?hl=en&p=mgmt_classic ) Note the .addHeader("Authorization", "Bearer " + token), this is the important part of the request, the "token" var is the access_token, you NEED add this Authorization header in order to use the API and don't forget to refresh when it expires, as explained here : https://developers.google.com/identity/protocols/OAuth2ForDevices in the "Using a refresh token" part.
And that's it, you can now print something sending a POST request to the "submit" method of the google cloud print API, I recommend to go here: https://developers.google.com/cloud-print/docs/appInterfaces and see all the methods available and how to use them (wich parameters send to them, etc). Of course in that link explains the "submit" method too.
EDIT:
EXAMPLE OF HOW TO SEND A REQUEST TO "/submit" FOR PRINTING USING ION LIBRARY AND MJSON LIBRARY (https://bolerio.github.io/mjson/) THE MJSON IS FOR CREATING A JSON OBJECT, YOU CAN CREATE IT THE WAY YOU PREFER
private void printPdf(String pdfPath, String printerId) {
String url = URLBASE + "submit";
Ion.with(this)
.load("POST", url)
.addHeader("Authorization", "Bearer " + YOUR_ACCESS_TOKEN)
.setMultipartParameter("printerid", printerId)
.setMultipartParameter("title", "print test")
.setMultipartParameter("ticket", getTicket())
.setMultipartFile("content", "application/pdf", new File(pdfPath))
.asString()
.withResponse()
.setCallback(new FutureCallback<Response<String>>() {
#Override
public void onCompleted(Exception e, Response<String> result) {
if (e == null) {
Log.d(TAG, "PRINTTT CODE: " + result.getHeaders().code() +
", RESPONSE: " + result.getResult());
Json j = Json.read(result.getResult());
if (j.at("success").asBoolean()) {
Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this, "ERROR", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(MainActivity.this, "ERROR", Toast.LENGTH_LONG).show();
Log.d(TAG, e.toString());
}
}
});
}
private String getTicket() {
Json ticket = Json.object();
Json print = Json.object();
ticket.set("version", "1.0");
print.set("vendor_ticket_item", Json.array());
print.set("color", Json.object("type", "STANDARD_MONOCHROME"));
print.set("copies", Json.object("copies", 1));
ticket.set("print", print);
return ticket.toString();
}
Yes, You can achieve silent print using this REST API(https://www.google.com/cloudprint/submit) ,I have done it using WCF Service.
you need to download contents from url as base64 content, then add
contentType=dataUrl
in the request.
Here is the code..
postData = "printerid=" + PrinterId;
postData += "&title=" + JobTitle;
postData += "&ticket=" + ticket;
postData += "&content=data:" + documentContent.ContentType + ";base64," + documentContent.Base64Content;
postData += "&contentType=dataUrl";
postData += "&tag=test";
Then , please make a request to submit REST API in this way.
var request = (HttpWebRequest)WebRequest.Create("https://www.google.com/cloudprint/submit");
var data = Encoding.ASCII.GetBytes(postData);
request.Headers.Add("Authorization: Bearer " + Token);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
request.UseDefaultCredentials = true;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
PrintJobResponse printInfo = json_serializer.Deserialize<PrintJobResponse>(responseString);
return printInfo;
Thanks.
For anybody reading this now, after a lot of searching around I have found it is a lot easier and faster to set up to just use Zapier to catch a hook and print to google cloud print (from cordova at least, i can't speak for native apps)

How do I publish a check in to facebook with android SDK

The docs are terrible. I want to publish a users check in to facebook. According to the docs creating a checkin object is deprecated
https://developers.facebook.com/docs/reference/api/checkin
and instead you're supposed to add a post with location data attached. So that's what I'm trying to do. Or maybe i'm supposed to try to publish and open graph story?
Anyways here's what I have, it's basically the code to publish a post that is in their SDK sample, the post is created but there is no location data attached.
private void publishStory() {
Session session = Session.getActiveSession();
if (session != null) {
Bundle placeBundle = new Bundle();
Bundle locationBundle = new Bundle();
Bundle postParams = new Bundle();
locationBundle.putString("latitude",String.valueOf(place.getLat()));
locationBundle.putString("longitude",String.valueOf(place.getLng()));
placeBundle.putString("id", place.getPage_id());
placeBundle.putString("name", place.getName());
placeBundle.putBundle("location", locationBundle);
postParams.putBundle("place", placeBundle);
postParams.putString("message", "test message");
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
String postId = null;
try {
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
postId = graphResponse.getString("id");
}
catch (JSONException e) {
Log.i(app.TAG, "JSON error " + e.getMessage());
}
catch(Exception e){
e.printStackTrace();
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(mContext, error.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(mContext, postId, Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
else {
toast("no session to publish");
}
}
the session does have publish permissions and it WILL publish a post but all that is there is the "test message" string. The place object is from facebook's servers so it is an actual place with a page_id. When i'm debugging the post params look something like this
Bundle[{message=test message, place=Bundle[{id=171229079554355, location=Bundle[{longitude=-122.434568, latitude=37.797314}], name=The Brixton San Francisco}]}]
Session.openActiveSession(activity, true, new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session, SessionState state,
Exception exception) {
if (session != null && session.isOpened()) {
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
activity, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("message", message);
postParams.putString("tags",tag);
postParams.putString("place",place_id);
Request.Callback callback = new Request.Callback() {
private String toastmessage;
public void onCompleted(Response response) {
try {
JSONObject graphResponse = response
.getGraphObject().getInnerJSONObject();
String postId = null;
postId = graphResponse.getString("id");
} catch (Exception e) {
Log.i("Test", "JSON error " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
isPosted(false);
Toast.makeText(
activity.getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
isPosted(true);
toastmessage = "Posted Successfully";
Toast.makeText(activity, toastmessage,
Toast.LENGTH_SHORT).show();
{
}
}
}
};
Request request = new Request(session, "me/feed",
postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
});