I'm trying to work with Facebook in my ASP.NET site where I have a logged in user of my site enter in text in a box for their status on my site. I want them to be able to push that status to FB as well per their permission. I did it using simple Facebook Connect JS code but I want to get the info in .NET and push it that way. I'm not actually creating a FB app for a FB profile though.
This is pseudo-code for what I want:
Facebook fb = new Facebook(apiKey);
FBSession sess = fb.Authenticate();
if(sess.isAuthenticated) {
User u = fb.getUser(sess.userId);
u.setStatus(Textbox1.text);
u.SaveStatus();
}
Does anything like this even exist for .NET or is their API for PHP only?
Sure, here is some sample code. It's using the Facebook Developer Toolkit (you can find it on codeplex). And FBConnectAuth which can also be found on codeplex.
You want to check the cookies to make sure that the cookie is real (making sure someone is not trying to hack in); which is why the cookie validation step is important.
As long as you login using the JS code, the same cookies that are set in the JS are accessible in C#.
This works fine for a Facebook Connect app.
using FBConnectAuth;
using facebook;
public facebook.API api = new facebook.API();
bool IsLoggedInToFacebook = false;
FBConnectAuthentication auth = new FBConnectAuthentication(ConfigurationManager.AppSettings["AppKey"], ConfigurationManager.AppSettings["Secret"]);
if (auth.Validate() != ValidationState.Valid)
{
IsLoggedInToFacebook = false;
}
else
{
FBConnectSession fbSession = auth.GetSession();
string userId = fbSession.UserID;
string sessionKey = fbSession.SessionKey;
api.ApplicationKey = ConfigurationManager.AppSettings["AppKey"];
api.SessionKey = sessionKey;
api.Secret = ConfigurationManager.AppSettings["Secret"];
api.uid = Convert.ToInt64(userId);
api.status.set("statutes text goes here")
IsLoggedInToFacebook = true;
}
Related
For GDPR compliance reasons, we have disabled link tracking in our Android and iOS applications and using generate Short URL method for getting the short link of the item, we want to share. But when we are calling generateShortUrl() method, it gives "Trouble creating a URL. Tracking is disabled. Requested operation cannot be completed when tracking is disabled" error and the URL that is returned does not work when shared on Facebook or an email when the user clicks on it.
Our concern is though tracking is disabled and Branch is unable to create a short URL, it shall return the working long URL at least. Please let us know if we have to do something here to make it work on our apps.
Can you please check if you set generateShortUrl like the following example codes for Android? You can also find detailed information about creating deep link
Android : https://docs.branch.io/apps/android/#create-deep-link
iOS : https://docs.branch.io/apps/ios/#create-deep-link
.
import io.branch.indexing.BranchUniversalObject;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
import io.branch.referral.util.LinkProperties;
BranchUniversalObject buo = new BranchUniversalObject();
LinkProperties lp = new LinkProperties();
buo.generateShortUrl(this, lp, new Branch.BranchLinkCreateListener() {
#Override
public void onLinkCreate(String url, BranchError error) {
if (error == null) {
Log.i("BRANCH SDK", "got my Branch link to share: " + url);
}
}
});
Also, if you have any further questions, please contact support#branch.io to give better assistance.
I've read the tutorials to log into a website prior to scraping it, but it just ain't workin'. I constructed a HttpIdentity object, added it to the Identities collection, and processed the request, but the page returned to scrape was still the login page. There isn't a lot about this on their website and documentation. Here's my code for that:
var identity = new HttpIdentity
{
UseCookies = true,
NetworkUsername = _username,
NetworkPassword = _password
};
Identities.Add(identity);
Request(_uri, Parse, identity);
In the Parse method I get a Response object returned with a Status Code of 200, and the "WasSuccessful" property of Response is "true". It seems that I should be redirected to the page I was trying to access, but I'm just getting the login html.
Is there something I'm missing?
I wasn't able to find a solution using the Iron Web Scraper, but I was able to do it with ScrapySharp, which is a free utility, so it worked out. ScrapySharp is able to mimic a browser to a degree, so navigation and submitting forms is pretty easy.
var browser = new ScrapingBrowser();
var homepage = browser.NavigateToPage(_Uri); // login Uri
var form = homepage.FindForm("login"); // get form by name
form.Method = HttpVerb.Post;
form["username"] = "my_username"; // get form fields by id
form["password"] = "my_password";
var resultPage = form.Submit(); // login
var loggedInPage = browser.NavigateToPage(new Uri("https://path.to.target.page"));
And that's it. I'm not sure what the problem was with Iron Web Scraper. Maybe some ajax on the login page. In any case, this code is working for me now.
I am developing an UWP application with a camera feature, I have studied this sets of codes,
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CameraStarterKit
And successfully developed a camera feature on my application. However, in my application, I wish to not store the picture into my local machine as the application is actually like a kiosk system whereby everyone will be using the same machine to take the picture.
What I am planning to do is actually to allow users to send the picture that they have taken to their own email address via the kiosk system. When they have taken a photo, a preview will be shown, and only if the user want to send the picture, then will the picture be "save"
The codes for my take photo function is something like this:
rivate async Task TakePhotoAsync()
{
var stream = new InMemoryRandomAccessStream();
Debug.WriteLine("Taking photo...");
await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
try
{
var file = await _captureFolder.CreateFileAsync("SimplePhoto.jpg", CreationCollisionOption.GenerateUniqueName);
Debug.WriteLine("Photo taken! Saving to " + file.Path);
var photoOrientation = CameraRotationHelper.ConvertSimpleOrientationToPhotoOrientation(_rotationHelper.GetCameraCaptureOrientation());
await ReencodeAndSavePhotoAsync(stream, file, photoOrientation);
Debug.WriteLine("Photo saved!");
}
catch (Exception ex)
{
// File I/O errors are reported as exceptions
Debug.WriteLine("Exception when taking a photo: " + ex.ToString());
}
}
And to get the preview of the picture will be:
private async Task GetPreviewFrameAsSoftwareBitmapAsync()
{
// Get information about the preview
var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
// Create the video frame to request a SoftwareBitmap preview frame
var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height);
// Capture the preview frame
using (var currentFrame = await _mediaCapture.GetPreviewFrameAsync(videoFrame))
{
// Collect the resulting frame
SoftwareBitmap previewFrame = currentFrame.SoftwareBitmap;
// Show the frame information
FrameInfoTextBlock.Text = String.Format("{0}x{1} {2}", previewFrame.PixelWidth, previewFrame.PixelHeight, previewFrame.BitmapPixelFormat);
// Create a SoftwareBitmapSource to display the SoftwareBitmap to the user
var sbSource = new SoftwareBitmapSource();
await sbSource.SetBitmapAsync(previewFrame);
// Display it in the Image control
PreviewFrameImage.Source = sbSource;
}
}
There are (at least) two ways:
1) "Better" one:
Create a backend that sends email using SmtpClient
Post your image from UWP to backend using HttpClient
2) "Easier" one: launch Mail app
The downside is that users will be able to edit the message, receiver and things like that.
Also you can try to use SmtpClient directly from UWP client (may be now with .Net Standard 2.0 it would be possible but I guess no one yet tried) or third-party open-source replacement (which might be a bit outdated as it was created for Windows 8) or even try to launch your backend as Windows Service on the client machine.
I can download logs file via analytics console > Devices > Device Search > Device Information > Download Logs
we can search the logs file by deviceId.
My question is How to know the deviceid from the user ??
For example, there is some problem on the application, the user reports to the admin, and the admin searchs the user device by deviceId.
Is there a code to display deviceId on my application, so the user can send the deviceId to the admin ??
Of course, there is a JavaScript API to get the Device ID.
See WL.Device.getID()
I have seen folks use code like this in Native apps and have some special view to show it t the user
NSUUID *oNSUUID = [[UIDevice currentDevice] identifierForVendor];
or
import android.provider.Settings.Secure;
private String android_id =
Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
I have not found an example of this API in JavaScript, but it is very easy to pass the data up from native, for example
in main.m
#import "WL.h"
NSDictionary *data = #{#"id": oNSUUID};
[[WL sharedInstance] sendActionToJS:#"DeviceInfo"
withData:data];
in your app
//global
var nativeInfo = null;
// in wlCommonInit()
var actionReceiver = function(received){
WL.Logger.error(received);
if ( received.action == "DeviceInfo"){
nativeInfo = received.data;
}
};
WL.App.addActionReceiver ("GarantiActionReceiver", actionReceiver);
I would like to know if its possible to get full screen snapshots from an air application.
What i am interested in, is functionality similar to PrintScreen button in windows, which takes snapshots of all screens, including third party application windows, not just window in which air app is running.
If its not specific to air, and flash/flex API can provide such functionality, it also would be great.
Thanx a lot in advance.
Check out this article as it explains obtaining a screenshot by calling a native process:
import flash.filesystem.File;
import flash.events.NativeProcessExitEvent;
var process:NativeProcess;
if(NativeProcess.isSupported) {
var file:File = File.applicationDirectory;
var args:Vector.<String> = new Vector.<String>();
if (Capabilities.os.toLowerCase().indexOf("win") > -1) {
file = file.resolvePath("PATH/TO/WINDOWS/printscr");
//use your prefered screenshot tool here (e.g. https://code.google.com/p/screenshot-cmd/
//also setup the args as needed
} else if (Capabilities.os.toLowerCase().indexOf("mac") > -1) {
file = file.resolvePath("/usr/sbin/screencapture");
args[0] = "-i";
args[1] = "screencapture.png";
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.arguments = args;
nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.workingDirectory = File.desktopDirectory;
process = new NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(NativeProcessExitEvent.EXIT,done);
}else trace("NativeProcess NOT SUPPORTED!");
function done(e:NativeProcessExitEvent):void{
trace("screenshot comprete");
}
One important thing to bear in mind is the AIR device profile.
If you're initially testing in ADL, be sure to use the extendedDesktop profile, otherwise NativeProcess.isSupported will return false.
For more details check out the NativeProcess documentation and the Communicating with native processes in AIR developer guide