I'm trying to post an image to twitter from my unity application.
My goal is to let the player tweet an image to their tweeter account.
I tried
Application.OpenURL("http://twitter.com/intent/tweet/?text=a message to be tweeted");
This is perfect because the players will have to enter their username and password in their own browser.
but I want to add an image as well.
I Tried to change the
?text=
to
?media=
I have seen in a website that twitter accepts an "media" parameter but since Application.OpenURL(""); accepts string, I couldn't pass byte[] of the image that I want to post to this URL to see whether it works or not.
I used Convert.ToBase64String(byte[] data) but for some reason, the Application.OpenURL(""); doesn't work with it. i assume it's because the length of the string that i made from the byte[] becomes so long.
I also searched google a lot for ways to login to twitter or post an image but they're mostly using third-party libararies and most of answers that are look good are written in asp mvc not unity.
thanks in advance.
Reading their documentation, if you WANT to pass the media as a string, use media_data instead of media. You will need to look online for how to convert the byte[] to a Base64 string.
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload
Also, you will need to specify the media_category to let Twitter know that it is a tweet_image.
Related
I'm trying to set up a basic app to call the Google Directions API from a Xamarin.Forms app in Android. I'm new to Xamarin & C# generally, so have struggled searching for the right terms, but am familiar with the directions service from a javascript angle.
I'm using this basic app as a test bed: https://learn.microsoft.com/en-us/xamarin/android/platform/maps-and-location/maps/maps-api
I can add the button and associate a process with it, but how do i call the API & catch the results?
I'll worry about plotting etc later, i just want to write out the results to console for now.
Thanks for your help in advance!
1.First of all, you can used following URL to get Json data.(Please notice:You need to enable the Directions API in Google console,otherwise, you will get error message This API project is not authorized to use this API.)
https://maps.googleapis.com/maps/api/directions/json?origin=lat1,lon1&destination=lat2,lon2&key=yourApiKey
In this URL, you need to provide the latitude and longitude of Origin position and destination postion.API key(You can get the API key from a Google console)
2.You can play and just change variables in this link and open it in browser, to see the returning object like this screenshot.
3.When you receive the return object, you will need to parse it.(Prase json data:http://bsubramanyamraju.blogspot.com/2017/04/xamarinforms-consuming-rest-webserivce_17.html)
4.The distance will be at googleApiRouteObject.routes[0].legs[0].distance; There you will find a int representation in meeters, and string representation like 2km.
5.The waypoints will be coded in Polylines, you will need to parse them. You can find how to do that with code examples here: https://developers.google.com/maps/documentation/utilities/polylineutility
If you want to get the sample code, you can refer to this link.
https://agileapp.co/xamarin-forms-maps-polyline-route-highlighted-google-api
I'm trying to find a way to give my application a YouTube URL (as copied from the address bar in a browser) and extract the unique video ID from that URL. I want to stay away from regex or any other string manipulation as a solution since not all YouTube URLs are the same and may continue to change.
There has to be some way to use the YouTube API for .NET (specifically C# for my solution) to simply call a method/function, pass the method the URL for the video, and finally the method would return the video ID as a string.
I've been trying to find documentation on this and so far I can only find info on using methods to retrieve data about a video based on already having and providing the video ID - which I do not have at this point.
I recognize which part of the YouTube URLs identify the video, but the users of my application should not have to be concerned with that.
It would be greatly appreciated if anybody could help me find a solution here.
Thanks!
Unfortunately I do not think this will work. But then again, I don´t understand the problem you have with using the URL. The URL in itself is a kind of an ID and the v property of the URL specifies which video it is. It seems you already know this.
Regarding your problems with using an URL:
Not all YouTube URLs are the same
R: No, but it doesn´t matter because using RegEx you would only read the v property (v=-l6P7VFKnW8), alternatively the short be variant
YouTube URLs may continue to change
R: Yes, they may. However it is unlikely that YouTube would change the identifier anytime soon because of the effects it would have on API's and other infrastructure. Besides, if you have a pure and modular generic solution you wouldn´t have to change more than one RegEx to comply with the new Id.
Related: Youtube .NET Data API: Retrieve only videoID?
Related: C# regex to get video id from youtube and vimeo by url
I don't get this example
string text = "我喜欢跑步。";
TranslateClient client = new TranslateClient(/* Enter the URL of your site here */);
string translated = client.Translate(text, Language.ChineseSimplified, Language.English);
Console.WriteLine(translated);
// I like running.
It "says enter the url of your site here". I thought that is the site you want to translate but then the next line takes in some text to translate. I don't get it. Do I first have to download the page somehow then translate it? Is there no translate entire page?
Edit
It does not seem possible. It also seems I have to pay for this library to use it. Is there any free ones out there?
The URL in question is the site that's running the code. So if foo.com uses TranslateClient, "foo.com" should be the parameter. The text is the actual text you want to translate, as shown in the example.
I don't think it will translate a URL the way the web interface does, but I haven't tested.
Also, the API is no longer available for free use, and it looks like TranslateClient won't work for that, since it doesn't take a key.
You can look at whether the website translator would meet your needs.
I can't seem to find any code examples anywhere online that even hint at any way to use the Facebook API or Facebook SDK with C#.net (or even VB.net) to use the Facebook Credits features.
Does anyone know of any .Net examples that could help show how to use the Facebook Credits features?
Most of the calls required to use the credits API are actually just graph calls which will work fine with the C# SDK. The other stuff like the the callbacks you are going to have to do own your own.
Well i think the Documentation by Facebook is Sufficient enough.
I have not used Facebook C# SDK but For use in .Net you can simply use HttpRequest/HttpResponse classes to do Send/Recive data.
For parsing JSON you can use JSON.Net or use JavaScriptSerializer Class.
Here is an Example with JavaScriptSerializer. Its for Facebook Feeds but you can use somthing similar for Credits too.
I see this is an old one, i'd like to contribute, having just fought this fight, and resorted to using network monitor to capture the raw tcp traffic to figure out what was going on.
Facebook is NOT sending a content-type of json, its
"ContentType: application/x-www-form-urlencoded"
They aren't sending JSON!! they are sending a form post
This caused no end of grief for me. I'm including an actual network snag of their data. I have no idea what they are doing , and its directly against their documentation. https://developers.facebook.com/docs/credits/callback/
"signed_request=[The signed request]&buyer=[my id]&receiver=[my id]&order_id=247146405372045&order_info=%22100credits%22&test_mode=1&method=payments_get_items"
TO tie it more directly to the question, if you're using asp.net, you can just accept a form post. If you using WCF, its a hassle
Accept Stream as the input to your WCF method
parse it out,
//Get the Stream
var postStream = new StreamReader(input).ReadToEnd();
//parse the string
var vals = HttpUtility.ParseQueryString(postStream);
I wish to play video content (in a container) from my website/ blog when the page is loaded. This would be similar to that of YouTube, Dailymotion etc...
I would like to have the actual URL in the container which would then play the video at the location of the URL. The basic idea is to hide the actual URL from the user and make the person to view the video from the current page.
Could someone suggest some feasible ideas to accomplish this?
Thanks,
Vijay
A quick Google search turned up:
JW Player
There are other FLV players out there (this one also claims to handle MP4), and that's only one possible format. Any more detailed answer would require answering what format you want to serve up, whether you want streaming capabilities, etc.
What I've seen a lot of sites do (NBC Video Player for example), is the following:
Create a VideoPlayer.swf which has the video player functionality.
Pass in a cryptic key to the VideoPlayer.swf via swfobject and flashParams
VideoPlayer.swf sends that key to the server.
Server sends back video data somehow to VideoPlayer.swf and it does its thing.
If you go to this NBC Office episode at http://www.nbc.com/The_Office/video/episodes/#vid=1200746, and look at the source, you won't find that 1200746 value anywhere, so maybe it's not in flashParams. Looks like they store that in an init.xml file via <videoID> 1200746</videoID>, and they probably use SWFAddress to map that #vid=1200746 anchor to that xml file in VideoPlayer.swf, send it to their secure server, and return the video and ads they want.
Hope that helps,
Lance