Validate Foursquare URL for any user in javascript - jquery-validate

Can any one tell me that how validate the Foursquare URL in javascript function.
We had validate the facebbok URL by calling ajax call to graph api. Is there any such api in foursquare.
pls help me for this issue.

There's no API for foursquare which validates foursquare URLs.

function ajaxCallToValidateFoursquare(){
var CLIENT_ID = "xxxxxxxxxxx";
var CLIENT_SECRET = "xxxxxxxxxx";
var foursquareUrl="https://foursquare.com/v/mh31-headquarters/4e4d100a52b1075a63924a4a"
var validFoursquareUrl = "foursquare.com/";
if($("#foursquareUrl").val()!=null && $("#foursquareUrl").val() != ""){
if(foursquareUrl.indexOf(validFoursquareUrl) != -1){
var placeName=foursquareUrl.substring(foursquareUrl.lastIndexOf("/")+1);
var questionIndex = placeName.indexOf("?");
if(questionIndex > 0)
placeName = placeName.substring(0, questionIndex);
$.getJSON('https://api.foursquare.com/v2/venues/'+placeName+'?client_id='+CLIENT_ID+'&client_secret='+CLIENT_SECRET+'&v='+new Date().format("yyyymmdd"),function(data){
//get Response in JSON - data
});
}
}
}
here clientid and secretkey are your apps info from foursquare. and Date.format method returns current seconds.

Related

Parse Cloud Right Query to retrieve Friendslist and not (like Instagram)

I have the class "Users" the default of Parse Dashboad. I have also the class "Friends", where I store the friendships between users like this:
There are two columns, "toUser" and "fromUser", which are showing who of the two users sent the friend request. These two columns are Pointers(Pointer<_User>) to the Users Class.
My concept is to retrieve two lists:
1. Friendlist for the logged in user
2. Userlist of users (who are not friends with the logged in user)
What would be the appropriate queries for that?
The first one logically should not scan all the class Users because it may slow down the perfomance of the app which is using Ionic 3 and Angular 4
Thank you
you don't need another class to do so all you need is a relation column in the default user class
to add new friend you just need the following code
var friendtoadd
//this is the friend object from parse user class you want to add you can get it by anyway you want
var currentUser = Parse.User.current();
var relation = currentUser.relation("friends");
relation.add(friendtoadd)
currentUser.save();
to retrieve array of friends of logged in user you can use the following code
var currentUser = Parse.User.current();
var friendRelation = currentUser.relation('friends');
var env = this
friendRelation.query().find({
success: function(users) {
for (var i = 0; i< users.length; i++) {
var object = users[i];
env.friends.push(object)
console.log(env.friends)
}
}
});
// you should define friends = []; in the class
if I understood your question right you want to find the friend requests you sent, or the ones you received. because I don't see where you made a relation between the user and his friends.
this is the code if you want to do this using cloud code:
First I validated the parameters of the friendRequest being saved :
Parse.Cloud.beforeSave("Friends", function(request, response){
var friendRequest = request.object;
if (!friendRequest.has("toUser") || !friendRequest.has("fromUser")) {
response.error("Invalid parameters");
return;
}
response.success();
});
then I created two cloud functions, one for retrieving the sentRequests:
Parse.Cloud.define("getSentRequests", function(request, response){
var query = new Parse.Query("Friends");
query.equalTo("fromUser", request.user);
if (!request.master) {
query.find({ sessionToken: request.user.getSessionToken() }).then(function(friends){
response.success(friends);
});
}else{
query.find({useMasterKey:true}).then(function(friends){
response.success(friends);
});
}
});
and you can call this either from a logged in user or using the masterKey if you want, and the other query is for the recievedRequests:
Parse.Cloud.define("getRecievedRequests", function(request, response){
var query = new Parse.Query("Friends");
query.equalTo("toUser", request.user);
if (!request.master) {
query.find({ sessionToken: request.user.getSessionToken() }).then(function(users){
response.success(users);
});
}else{
query.find({useMasterKey:true}).then(function(users){
response.success(users);
});
}
});

How to call dynamic crm 2016 rest api from javascript?

I want to create lead in dynamic crm from my website. My website is build using HTML as this is a static site. I need to call dynamic crm (setup on premises) api from contact us page to submit data in dynamic crm.
Please suggest me a right direction.
Thanks
The SDK has lots of helpful information, have you looked at it? Here's a start:
Authenticating to CRM from JS using adal.js
Perform operations using the Web API
This is a sample code we use to submit entries from webpage to CRM. Hope this helps:
function CreateWebLeadInCRM(SourceCampaignName, Email, MobilePhone, FirstName, LastName, CompanyName){
var webLead = new Object();
//Add Source Campaing name
if(SourceCampaignName != null)
webLead.sof_sourcecampaign = SourceCampaignName;
//Add Email
if(Email != null)
webLead.sof_Email = Email;
//Add Mobile phone
if(MobilePhone != null)
webLead.sof_MobilePhone = MobilePhone;
//Add First name
if(FirstName != null)
webLead.sof_FirstName = FirstName;
//Add Last name
if(LastName != null)
webLead.sof_LastName = LastName;
//Add Company name
if(CompanyName != null)
webLead.sof_CompanyName = CompanyName;
var jsonwebLead = JSON.stringify(webLead);
var createwebLeadReq = new XMLHttpRequest();
createwebLeadReq.open("POST", "http://SERVER/ORG/XRMServices/2011/OrganizationData.svc/sof_webleadSet", true, "USERNAME", "PASSWORD");
createwebLeadReq.setRequestHeader("Accept", "application/json");
createwebLeadReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
createwebLeadReq.onreadystatechange = function () {
createwebLeadReqCallBack(this);
};
createwebLeadReq.send(jsonwebLead);
Ugly thing about this approach is that you have to save your password inside your javascript function, which is not really safe approach.. On the other hand you should only allow this user to insert entries to only one custom table without possibility to do anything else inside your CRM. This way you could manage what happens if you get spammed by the bots.

Yammer "Follow in Inbox" API support

My company has created a Yammer application that we use internally. Our app automatically subscribes people to various threads that have been created. We have found that there is a difference between "subscribing" someone to a thread and what happens when a user clicks the "follow in inbox" link on the site. When we automatically subscribe people, the only thing that we can see happening is that the thread will appear in the users "Following" section in the Home tab. Contrast this with what happens when a user clicks the "Follow in Inbox" link. From that point on any comments added to the thread will show up in the user's inbox and an email will be sent out to the user when this happens. We would really like for this to happen when we automatically subscribe someone to a thread, however, this feature seems to be missing from the REST API. Does anyone know of a way to accomplish this? The functionality provided by the subscription API endpoint is not sufficient for our purposes.
Thank you
P.S. I've sent the link to this question to several of my colleges they may respond before I get a chance to.
As a verified admin it is possible to create an impersonation token and then perform actions on behalf of the user such as join group/thread.
Note that for private groups, the group admin's are still required to approve the new member
https://developer.yammer.com/docs/impersonation
You can achieve your desired behaviour by adding users directly to the groups.
A C#.Net example I use:
// Impersonate user to join group
string ClientID = ConfigurationSettings.AppSettings["ClientID"]; // ClientID of custom app.
string userid = XMLDoc.Root.Element("response").Element("id").Value; // Yammer user id (in this case retreived from a previous API query)
string YammerGroupID = "123456"; // set group id.
string url = "https://www.yammer.com/api/v1/oauth/tokens.json?user_id=" + userid + "&consumer_key=" + ClientID; // impersonation end-point
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("Authorization", "Bearer " + bearer); // Bearer token of verified admin running the custom app.
request.Timeout = 90000;
request.Method = "GET";
request.ContentType = "application/json";
request.Proxy = new WebProxy() { UseDefaultCredentials = true };
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream);
string UserTokenJSON = reader.ReadToEnd(); // UserOAuth token as a JSON string.
string UserToken = UserTokenJSON.Substring(UserTokenJSON.IndexOf("token") + 8, 22); // Find 'token' in json string.
string temp = UserToken.Substring(UserToken.Length); // there is likely a much better way to parse out the token value, although this works.
temp = UserToken.Substring(UserToken.Length - 1);
temp = UserToken.Substring(UserToken.Length - 2);
if (UserToken.Substring(UserToken.Length) == "\\")
{ UserToken = UserToken.Substring(0, UserToken.Length); }
if (UserToken.Substring(UserToken.Length - 1) == "\"")
{ UserToken = UserToken.Substring(0, UserToken.Length - 1); }
if (UserToken.Substring(UserToken.Length - 2) == "\",")
{ UserToken = UserToken.Substring(0, UserToken.Length - 2); }
string url2 = "https://www.yammer.com/api/v1/group_memberships.json?group_id=" + YammerGroupID; // group membership endpoint,
HttpWebRequest request2;
request2 = (HttpWebRequest)WebRequest.Create(url2);
request2.Headers.Add("Authorization", "Bearer " + UserToken); // Impersonation Token
request2.Timeout = 90000;
request2.Method = "POST";
request2.ContentType = "application/json";
request2.Proxy = new WebProxy() { UseDefaultCredentials = true };
try
{
using (WebResponse response2 = (HttpWebResponse)request2.GetResponse())
{
confirmedstring += " New member: " + Email + "\\r\\n"; // This is used for posting summary back to a Yammer group in further code.
confirmedadditions++;
}
}
catch
{
Errorstring += "Error in adding " + Email + " to group " + YammerGroupID + "\\r\\n";
errors++;
}
}
}

How to perform a get request with RestSharp?

I'm having trouble figuring out how to make a GET request using RestSharp on Windows Phone 7. All of the examples show making a POST request, but I just need GET. How do I do this?
GET is the default method used by RestSharp, so if you don't specify a method, it will use GET:
var client = new RestClient("http://example.com");
var request = new RestRequest("api");
client.ExecuteAsync(request, response => {
// do something with the response
});
This code will make a GET request to http://example.com/api. If you need to add URL parameters you can do this:
var client = new RestClient("http://example.com");
var request = new RestRequest("api");
request.AddParameter("foo", "bar");
Which translates to http://example.com/api?foo=bar
What you're looking for is located here.
The code snippet that covers your scenario is below (request.Method should be set to Method.GET):
public void GetLabelFeed(string label, Action<Model.Feed> success, Action<string> failure)
{
string resource = "reader/api/0/stream/contents/user/-/label/" + label;
var request = GetBaseRequest();
request.Resource = resource;
request.Method = Method.GET;
request.AddParameter("n", 20); //number to return
_client.ExecuteAsync<Model.Feed>(request, (response) =>
{
if (response.ResponseStatus == ResponseStatus.Error)
{
failure(response.ErrorMessage);
}
else
{
success(response.Data);
}
});
}

Object XMLHttpRequest to JSON

I am creating an jquery ajax form which calls the method below
public string GetRestaurantInfo(string date, string pageId)
{
Node node = new Node(Convert.ToInt32(pageId));
string day = DateTime.Parse(date).DayOfWeek.ToString();
return JsonConvert.SerializeObject(GetOpeningHours(node, day));
}
private static object GetOpeningHours(Node node, string day)
{
XDocument xmlDoc = XDocument.Parse(node.GetProperty("openingHours").ToString());
var q = from item in xmlDoc.Descendants("scheduleItem")
where item.Element("weekDayLocal").Value == day
select new
{
day = item.Element("weekDayLocal").Value,
startTime = item.Element("firstSet").Element("hourStart").Value,
closingTime = item.Element("firstSet").Element("hourEnd").Value,
hoursOpen = 4
};
return q;
}
I would like the data to be returned in a JSON format, but it is returning the data in the following format
{"d":" [{\"day\":\"Tuesday\",\"startTime\":\"17:00\",\"closingTime\":\"11:00\",\"hoursOpen\":4}]"}
I am not sure how to resolve this? Any ideas?
Thanks in advance for any help
I assume this thread was not answered, and I found this thread when I Google as I faced the same issue too. After a struggle with Firebug, The solution was simple in the end. You just have to parse it twice as in the following code. But I am not sure whether this is the correct solution, or is this an impact in the web service call that I tried to make.
JSON.parse(JSON.parse(result).d)
Anyway just for some one who want to know the web service call,
xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
//xhr.responseText; this contains the data
}
}
};
xhr.send(params);
Thanks,
Sabo
Well that is jSon i suppose. Did you try doing below in the callback javascript function.
function callback(rslt,cntxt){
var result = Sys.Serialization.JavaScriptSerializer.deserialize(rslt);
console.dir(result);
}
watch the firebug console and inspect the object that was dumped.

Resources